I have an array of objects. How do I add an id key to them starting from 1.
[
{
color: \"red\",
value: \"#f00\"
},
{
color: \"green\",
value: \"
when i use this solutions my ids get one number like this:
list = [ {
color: "red",
value: "#f00",
id: 0
}, {
color: "green",
value: "#0f0",
id: 4
},{
color: "blue",
value: "#00f",
id: 4
},{
color: "cyan",
value: "#0ff",
id: 4
},{
color: "black",
value: "#000",
id: 4
}]
my code is this:
let i = 0;
list.map(n => {
n['id'] = i;
i++;
});