0

I have an array that conatins a list of objects, then am mapping through the object to display a list of data. Right now when user add item to the list , I want to change the index of that newly added Item to a string value.

What am getting is this

 [{…}]
0: {categories: 'A very nice shawarma for 2!', discount: 0, id: 7,}

Instead what I want is the index key 0 of the array to change to a string value rather than the automatic 0, 2,3... inedex key base

Something like ...

"String" : {categories: 'A very nice shawarma for 2!', discount: 0, id: 7,}
Chris Li
  • 2,628
  • 1
  • 8
  • 23
Ahmad Salihu
  • 55
  • 1
  • 6
  • You can't able to do that. You have to make the parent array to object to giving string key. Because Array in js is used only with numeric, auto-incremented keys, but javascript objects can hold named key-value pairs. – hamid mehmood Jul 17 '22 at 03:47
  • 1
    why would you use array if you dont want the number index, just use an object? – Chris Li Jul 17 '22 at 03:49

0 Answers0