【发布时间】:2020-11-26 18:39:09
【问题描述】:
我有一个这样的对象数组:
const customers = [
{
customer_name: 'Negan',
customer_age: 45,
customer_weapon: 'Bat',
customer_email: 'negan@sanctuary.com',
customer_city: 'Washington'
},
{
customer_name: 'Daryl',
customer_age: 41,
customer_weapon: 'Crossbow',
customer_email: 'daryl.dixon@kickass.com',
customer_city: 'Atlanta'
},
{
customer_name: 'Rick',
customer_age: 45,
customer_weapon: 'Magnum 357',
customer_email: 'rick@alexandria.com',
customer_city: 'King County'
},
]
我想用这些键替换对象内的所有键:
const newKeys = [
'firstname',
'age',
'weapon',
'email',
'city'
]
最好的方法是什么?一个例子将不胜感激!
【问题讨论】:
-
您能告诉我们您的尝试吗?我们帮助纠正你的缺陷,而不是给你代码
-
注意:每个人都应该知道这样一个事实,即任何仅基于替换键列表的方法实际上仅限于一种客户对象的键顺序(和结构)。环境始终必须确保每个客户对象的密钥创建顺序相同。
标签: javascript arrays object ecmascript-6