var arr1 = [1,1,1,2,2,3,3];
var arr2 = [[],[],[]];
for (x in arr1){
var i = arr1[x]-1;
arr2[i].push(arr1[x]); }
这段JS代码不正确在哪里?怎么修正呢?
JS?ARRAY?FOR?IN
JS
ARRAY
FOR
IN
------解决方案--------------------
没有问题
var arr1 = [1,1,1,2,2,3,3];1,1,1,2,2,3,3
var arr2 = [[],[],[]];
for (x in arr1){
var i = arr1[x]-1;
arr2[i].push(arr1[x]);
}
document.write(arr2);