如题不想用jquery的getOwnPropertyNamesvar getProperty = function(obj) { var nArr = []; for (var i in obj) { nArr.push[i]; } console.log(nArr); return nArr;}getProperty({a:1,b:2})最后返回的结果是[];如果换成var getProperty = function(obj) { var nArr = [], k = 0; for (var i in obj) { nArr[k] = i; k++; } console.log(nArr); return nArr;}getProperty({a:1,b:2});则可以返回正确的结果['a','b'],为何
添加回答
举报
0/150
提交
取消