How To Add A Key Value Into Pair In Existing Local Storage Object?
I am trying to add a key value pair into an existing localstorage object, below is what the object looks like: category: [{'category_id':1,'name':'Default Category','position':1},{
Solution 1:
You can loop through each object in the array and simply add whatever you want.
let arr = [{
"category_id": 1,
"name": "Default Category",
"position": 1
}, {
"category_id": 2,
"name": "Tech",
"position": 1
}];
var levelCount = 1;
for (let el of arr) {
el.level = levelCount;
levelCount++;
}
console.log(arr);
Post a Comment for "How To Add A Key Value Into Pair In Existing Local Storage Object?"