JS遍历数组

使用prototype

[javascript]

var str = ["a","b"];Array.prototype.f=function(){}
for(var key in str){

console.log(key + "::" + (str[key] + ""));
}
// 0::a VM349:4
// 1::b VM349:4
// f::function (){}

[/javascript]

遍历数组

[javascript]

for(var key in str){

console.log(key + "::" + (str[key] + ""));

}

for(var key=0;key<str.lengh;key++){

console.log(key + "::" + (str[key] + ""));

}

[/javascript]

您的赞助将会支持作者创作及本站运维

发表评论


TOP