【发布时间】:2022-11-03 02:31:49
【问题描述】:
我想在对象的对象内转换值。像这样的东西:
初始对象:
const studentDetails = {
'details1': {Name: "John", CountryName: "US", value: 1},
'details2': {Name: "David", CountryName: "AUS", value: 2},
'details3': {Name: "Bob", CountryName: "UK", value: 3},
};
变换对象:
{
'details1': {Name: "John", CountryName: "US", value: 2},
'details2': {Name: "David", CountryName: "AUS", value: 3},
'details3': {Name: "Bob", CountryName: "UK", value: 4},
};
我已经做了类似的事情,但无法弄清楚
Object.fromEntries(Object.entries(studentDetails).map(([key,
value]) => [key, some data transformation on value]))
【问题讨论】:
-
所以你只是在增加价值?
-
它可以是值键上的任何转换,例如递增、平方、除法等
标签: javascript object transformation