JS里不管是关联数组还是索引数组都可以用for来循环,示例代码如下:
一、索引数组:
var test = new Array(2222,33333,444444,55555555,666666);
for(i in test){
console.log(i + ' ' + test[i]);
}
打印结果:
二、关联数组:
var test = new Array();
test['a'] = 'aaaa';
test['b'] = 'bbbb';
test['c'] = 'cccc';
for(i in test){
console.log(i + ' ' + test[i]);
}
打印结果:
「真诚赞赏,手留余香」

- 本站文章除注明转载外,均为本站原创
- 欢迎任何形式的转载,但请务必注明出处,尊重他人劳动
- 转载请注明:文章转载自:Marser [https://www.marser.cn]
- 本文标题:JS关联数组和索引数组的循环
- 本文固定链接: https://www.marser.cnarticle/10.html