📜  javascript循环使用函数替换对象值 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:58.200000             🧑  作者: Mango

代码示例1
const data = [
  { foo: 1, bar: 2 }, 
  { foo: 2, bar: 3 },
  { foo: 3, bar: 4 },
];

const increment = a => a + 1;

const result = data.map(o => ({ ...o, foo: increment(o.foo) }));
console.log(result);
 Run code snippet