Search code examples
javascriptarrayskeyflat

JAVASCRIPT remove parent key from array


I have an array and i need to remove the top most 0 key, and leave the array with the following structure:

[array(24)]

0:{...}

1:{...}

2:{...}

3:{...}

until last key (24)

Right now this is how the array is:

enter image description here

I have tried many methods like assign, flat, array_shift, Object.keys(), Object.values(), and others without any luck.


Solution

  • There is a designated function for it. Try myArray.shift()

    const myArray = [{a:1}, {b:2}, {c:3}]
    const firstElement = myArray.shift();
    console.log(`first element: ${JSON.stringify(firstElement)}`)
    console.log(`modified Array: ${JSON.stringify(myArray)}`)