let prices = { banana: 1, orange: 2, meat: 4, }; let doublePrices = Object.fromEntries( // 转换为数组,以后使用 map 方法,而后经过 fromEntries 再转回到对象 Object.entries(prices).map(([key, value]) => [key, value * 2]) ); alert(doublePrices.meat); // 8
let prices = { banana: 1, orange: 2, meat: 4, }; let doublePrices = Object.fromEntries( // 转换为数组,以后使用 map 方法,而后经过 fromEntries 再转回到对象 Object.entries(prices).map(([key, value]) => [key, value * 2]) ); alert(doublePrices.meat); // 8