数组中的对象添加属性(vue中使用)
- 定义在methods
fun:(arr)=>{
let _arr = [];
arr.map((item,index)=>{
_arr.push(Object.assign({},item,{key:index}));
})
return _arr;
}
- 使用
let oldArr = [{a:1,b:2},{a:1,b:2}]
let newArr = [];
newArr = this.fun(oldArr );
console.log(newArr)