Java和js中用於遍歷的循環,得到結果的區別

js中的獨有的循環是for…in,用於遍歷數組的下標或對象的成員。web var a = ['tom','jack','rose']; for (var item in a) { alert(item); } 這裏輸出的是0,1,2。 而Java中獨有的循環forEach,用於遍歷數組集合或對象。數組 int[] a = {100,200,300,400}; //遍歷數組 for (i
相關文章
相關標籤/搜索