-2

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.

André Castro
  • 1,527
  • 6
  • 33
  • 60
  • what about [`Array#shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)? – Nina Scholz Feb 27 '21 at 08:56
  • It gives me undefined when i log the resulting array. – André Castro Feb 27 '21 at 09:09
  • please add the array and wanted result in text form. – Nina Scholz Feb 27 '21 at 09:11
  • Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan Feb 27 '21 at 09:13
  • The array with the objects seems to be inside another array – Thomas Feb 27 '21 at 11:41

3 Answers3

0

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)}`)
Tamir Nakar
  • 933
  • 1
  • 10
  • 17
0

You can use Object.values

myarray = {
    Array24 :
    {
        '0': { category :'saude'},
        '1': {price: '40'},
        '2': { category :'saude'},
        '3': {price: '40'},
        '4': { category :'saude'},
        '5': {price: '40'},
    }
}

console.log(Object.values(myarray));

You will get

  {
    '0': { category: 'saude' },
    '1': { price: '40' },
    '2': { category: 'saude' },
    '3': { price: '40' },
    '4': { category: 'saude' },
    '5': { price: '40' }
  }
]
Richard Rublev
  • 7,718
  • 16
  • 77
  • 121
0

Try using shift method, like:

const arr = [1, 2, 3, 4, 5];
arr.shift();
console.log(arr);
AdriSolid
  • 2,570
  • 1
  • 7
  • 17