If I have an array that looks like:
arr =[ { id: ‘f794’,label: ‘Blue Bird’ } ]
how do I give the element of it a key so I get
arr =["myKey":{ id: 'f794',label: 'Blue Bird' } ]
I have tried several different ways, like
arr[0]= '"myKey"' + ":" + arr[0]
which gives me
[ "myKey:[object Object]" ]
How do I get arr =["myKey":{ id: 'f794',label: 'Blue Bird' } ]
Thanks
2
Answers
You can do :
With perhaps a specific key for each element depending on what you want to do with it.
Here is how:
Or the shorthand equivalent: