I have an array let labels = ['Apple', 'Banana', 'Pear']
.
I want to map the array to a JSON output {'Apple':0, 'Banana':0, 'Pear':0}
.
I am using the script:
let output = labels.map(function(item) {
return { item: 0 };
});
which gives me:
[{"item": 0}, {"item": 0}, {"item": 0}]
How do I pass the variable item into the JSON output?