Object array clone with subset of properties

后端 未结 3 1334
执笔经年
执笔经年 2020-12-18 09:40

What is the most efficient way in JavaScript to clone an array of uniform objects into one with a subset of properties for each object?

UPDATE

3条回答
  •  不思量自难忘°
    2020-12-18 09:48

    using Object Destructuring and Property Shorthand

    let array = [{ a: 5, b: 6, c: 7 }, { a: 8, b: 9, c: 10 }];
    let cloned = array.map(({ a, c }) => ({ a, c }));
    
    console.log(cloned); // [{ a: 5, c: 7 }, { a: 8, c: 10 }]
    

提交回复
热议问题