js中遍历对象属性

/*js中遍历对象属性*/
function printObject(obj) {var temp = "";for (var key in obj) {temp += key + ":" + obj[key] + "n";}return temp;
}/*测试用例*/
var obj = {"a": "1", "b": "2"};
console.log(printObject(obj));

 

Published by

风君子

独自遨游何稽首 揭天掀地慰生平