My array contains elements with both id
and des
properties. I would like to add an additional property like value:0
to each object in the array. I achieved this using a loop.
let data = [
{
"id": 1001,
"des": "aaa"
},
{
"id": 1002,
"des": "aaa"
}
];
for (let i = 0; i < data.length; i++) {
let tempObj = {
"id": data[i].id, "des": data[i].des, "value": 0
}
data[i] = tempObj;
}
Is there a way to accomplish this without using a loop in JavaScript? Are there any built-in JavaScript functions that can help with this?