【js】替换数组中的某个对象

  • Post author:
  • Post category:其他


对对象属性进行判断,满足则替换

var asd = {name: '李四', age: 12};
let list = [
	{name: '张三'},
	{name: '李四'}
]
list = list.map(t => {
    return t.name === asd.name ? asd: t;
  });
 console.log(list)