I've found similar but not understanding what is done wrong still. Am learning I know... I was trying to use technique like in this answer but am not sure if it is right way and can not get it to work. I get TypeError: Invalid attempt to destructure non-iterable instance.
I wish for array of string like; ['One', 'Two', 'Three'] to become object like below. Where I want to turn the array into an object with specific key that holds array of objects with those values as specific key/value object like below.
{
items: [
{
label: 'One',
id: 1
},
{
label: 'Two',
id: 2
},
{
label: 'Three',
id: 3
},
]
}
I try like
let arrayOfStrings = ['One', 'Two', 'Three']
const [label, id] = arrayOfStrings;
arrayOfStrings = [label, id];
document.write(arrayOfStrings);
Any guidance much appreciated!
"One"should be1? Is it because you are starting with1and counting up (as opposed to a0index), or is it because the string"One"is an English word corresponding to the number1? Or some other reason? It would be helpful if you explicitly lay out your needs.