js常用方法

110 阅读1分钟
json数组的合并新属性      let arr = [        { id: 1, name: "dylan" },        { id: 2, name: "kebi" },      ];      let arr1 = [        { id: 1, position: "ceo" },        { id: 3, position: "sales" },      ];      let list = arr.reduce((pre, cur) => {        let target = pre.find((ee) => ee.id == cur.id);        if (target) {          Object.assign(target, cur);        } else {          pre.push(cur);        }        return pre;      }, arr1);      console.log(list);