jq遍历对象,Jquery遍历对象,用forEach遍历对象
var m = new Map();
m.set(1, "black");
m.set(2, "red");
m.set("colors", 2);
m.set({x:1}, 3);
//mapObj对象可以理解为m,
m.forEach(function (item, key, mapObj) {
debugger;
document.write(item.toString() + "<br />");
document.write(key.toString() + "<br />");
document.write(mapObj.toString() + "<br />");
document.write("===================================");
m.set(1, "black");
m.set(2, "red");
m.set("colors", 2);
m.set({x:1}, 3);
//mapObj对象可以理解为m,
m.forEach(function (item, key, mapObj) {
debugger;
document.write(item.toString() + "<br />");
document.write(key.toString() + "<br />");
document.write(mapObj.toString() + "<br />");
document.write("===================================");
});
运行结果: