let jsonData = {'widgets':[]};
for(let i=0;i<Math.pow(10,5);i++){
let temp = {'id':'widget'+i,'type':i+1,'priority':i+2};
jsonData.widgets.push(temp);
}
console.log(jsonData)
// 定义要替换的元素
const newWidget = {
"id": "widget1",
"type": "line-chart",
"priority": 1
};
var start = performance.now();
const widgetMap = new Map();
jsonData.widgets.forEach(widget => {
widgetMap.set(widget.id, widget);
});
// 使用Map的方式
widgetMap.set(newWidget.id, newWidget);
var end = performance.now();
console.log('cost is', `${end - start}ms`)
console