how to add id in array javascript
let data = [{
color: "red",
value: "#f00"
}, {
color: "green",
value: "#0f0"
}, {
color: "blue",
value: "#00f"
}, {
color: "cyan",
value: "#0ff"
}, {
color: "magenta",
value: "#f0f"
}, {
color: "green",
value: "#ff0"
}, {
color: "black",
value: "#000"
}];
data.forEach((o, i) => o.id = i + 1);
console.log(data);