Add key value pair to all objects in array

后端 未结 10 1894
醉酒成梦
醉酒成梦 2020-12-04 10:43

I wanted to add a key:value parameter to all the objects in an array.

eg:

var arrOfObj = [{name: \'eve\'},{name:\'john\'},{name:\'jane\'}];
<         


        
10条回答
  •  一向
    一向 (楼主)
    2020-12-04 11:24

    You may also try this:

    arrOfObj.forEach(function(item){item.isActive = true;});
    
    console.log(arrOfObj);
    

提交回复
热议问题