4 回答
TA贡献1828条经验 获得超4个赞
您可以 flatMap 对象的值。
var descriptions = { 1: { description: "abc" }, 2: { description: "def" }, 3: { description: "ghi" } },
values = Object.values(descriptions).flatMap(Object.values);
console.log(values);
TA贡献1836条经验 获得超3个赞
const obj = {
descriptions: {
1: {
description: "abc"
},
2: {
description: "def"
},
3: {
description: "ghi"
}
}
};
console.log(Object.values(obj.descriptions).map(({description}) => description))
TA贡献1802条经验 获得超5个赞
或类似的东西
function f(obj) {
let array = []
for (const prop in obj) {
array.push(Object.values(obj[prop])[0])
}
return array
}
TA贡献1862条经验 获得超6个赞
descriptions= {
1: {
description: "abc"
},
2: {
description: "def"
},
3: {
description: "ghi"
}
}
var keys = Object.keys(descriptions);
var values = keys.map((key) => descriptions[key].description);
values将是您要查找的数组。
添加回答
举报