数组对象添加属性

如何给一个数组对象的每一项新增一个属性 如:isSelected:true??

let newArr = arr.map(v=>{
      return {...v,isSelected:true}
})
let array = [{name: 'lili'}, {name:'petrel'}]
Array.from(array, item => item.isSelected = false)
console.log(array);
数组对象A,数组对象B,A中item.id === B中的item.id的对象新增属性isSelected:false,否则新增属性isSelected:true

const A=[{id: 1},{id:2}, {id: 4}]; const B=[{id: 1}, {id:2}, {id:3}]; const result = A.map(item => { return { ...item, isSelected: B.filter(i=>{ return item.id === i.id }).length > 0 } }) console.log(result)
上一篇:一次etcd查看数据的报错


下一篇:[转]etcdctl v2 v3 使用指南