2 回答
TA贡献1833条经验 获得超4个赞
您可以使用Object.keys和Object.values获取第一个键和值,如下所示
let arr = [{"M": {"usernameFormatOptionsCreate": {"SS": ["sms"]}}}, {"M": {"UsernameFormatOptionsChange": {"SS": ["sms"]}}}];
let output = arr.map(function(c){
let key = Object.keys(c.M)[0];
let value = Object.values(c.M[key])[0];
let result = {};
result[key] = value;
return result;
});
console.log(output)
TA贡献1776条经验 获得超12个赞
let input = [{"M": {"usernameFormatOptionsCreate": {"SS": ["sms"]}}}, {"M": {"UsernameFormatOptionsChange": {"SS": ["sms"]}}}];
let output = input.map(({M}) => {
let y = {};
Object.entries(M).forEach(([key, {SS}]) => {
y[key] = SS;
});
return y;
});
console.log(output);
添加回答
举报