如何更改对象数组中的键名?
var arrayObj = [{key1:'value1', key2:'value2'},{key1:'value1', key2:'value2'}];如何将每个key1更改为stroke,以便获得:
var arrayObj = [{stroke:'value1', key2:'value2'},{stroke:'value1', key2:'value2'}];发布于 2018-06-20 23:04:11
在最近的JavaScript (和TypeScript)中,使用destructuring with rest syntax、spread syntax和array map替换对象数组中的一个关键字符串。
const arrayOfObj = [{
key1: 'value1',
key2: 'value2'
}, {
key1: 'value1',
key2: 'value2'
}];
const newArrayOfObj = arrayOfObj.map(({
key1: stroke,
...rest
}) => ({
stroke,
...rest
}));
console.log(newArrayOfObj);
https://stackoverflow.com/questions/6809659
复制相似问题