javascript set all values in array of object

后端 未结 4 2016
时光说笑
时光说笑 2021-01-03 23:50

Two part question about similar problems. I\'ve got 2 different arrays,

array 1:

 array1 = [{
     name : \"users\",
     checked :          


        
4条回答
  •  孤街浪徒
    2021-01-04 00:25

    You can use es6 fat arrow and make one liner but still it involves iteration .

    array1.map(a=>a.checked=true);
    

    array1 = [{
         name : "users",
         checked : true
       }, {
         name : "active users",
         checked : false
       }, {
         name : "completions",
         checked : false
       }]
       array1.map(a=>a.checked=true);
       console.log(array1);

提交回复
热议问题