迭代数组:另一种方法

Iterating Arrays: another approach

本文关键字:方法 另一种 数组 迭代      更新时间:2023-09-26

你把for循环称为迭代数组的最佳方法,这让我很恼火,因为在数组内部,你需要手动获取迭代元素。在某些情况下,我发现了另一种更适合我的方法:

var data=['test1', 'test2', 'test3'], item=0, n=0;
while ((item=data[n++])) {
   // here you can use item instead of data[n]
}

问候,LX

如果数组包含0、false、null或其他" false "值,

将失败。

While将在数组中间退出