1 回答
TA贡献2080条经验 获得超4个赞
const data = {
"productName": {
"de-DE": "Hudson",
"en-US": "Hudson Wall Cup",
"fr-FR": "Hudson Wall Cup FR"
},
"productDescription": {
"en-US": "Wall Hanging Glass Flower Vase and Terrarium",
"it-IT": "Wall Hanging Glass Flower Vase and Terrarium IT"
},
"sizetypecolor": {
"en-US": "3 x 3 x 5 inches; 5.3 ounces"
},
"image": {
"en-US": [
{
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "Xc0ny7GWsMEMCeASWO2um"
}
}
],
"it-IT": [
{
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "Xc0ny7GWsMEMCeASWO2um"
}
}
]
},
"tags": {
"en-US": ["vase", "flowers", "accessories", "translation"],
"jp": ["vase", "flowers", "accessories", "translation"]
},
"website": {
"en-US": "http://www.amzon.com/dp/B00E82D7I8/"
}
}
function filter(object) {
return Object.entries(object).reduce((filtered, [key,val]) => {
if(typeof val === "object" && !Array.isArray(val)) filtered[key] = filter(val);
if(key === "en-US") filtered[key] = val;
return filtered;
},{})
}
console.log(filter(data))
添加回答
举报