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,}
2
  • 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. Commented Jul 17, 2022 at 3:47
  • 1
    why would you use array if you dont want the number index, just use an object? Commented Jul 17, 2022 at 3:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.