How to rename array keys to a string value in JavaScript

143 views Asked by At

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,}
0

There are 0 answers