1. The following code implements the ability to pass in an ARR array (the elements in the ARR array may have the same), create a new arr_new array, iterate through the ARR array with a For loop, and then determine the elements that are not duplicated and put into the arr_new array.
1 //gets the contents of the array that are not duplicates by passing in the array2 functionL_arr (Arr:array)3 {4 varArr_new:array =NewArray ();5 varTemp:int = 0;6 for(vari = 0; i < arr.length-1; i++ ){7 if(arr[i][0]!=arr[i+1][0]){8 9Arr_new[temp] = arr[i][0];Tentemp++; One } A } -Arr_new[temp] = arr[i][0]; - returnarr_new; the}
Attention:
If you accidentally write the 6th line in the above code for (var i = 0; i < arr.length; i++) , the following error will occur:typeerror:error #1010: The term has not been defined and no What property.
So in the future when writing code, you should pay attention to the bounds of the array traversal problem.
2. The function of the following code is to pass in the arr two-dimensional array, filtered to get all the remaining elements except arr[i][0].
1 //In addition to the first column, the rest of the content2 functionF_arr (Arr:array)3 {4 varArr_new:array =NewArray ();5 varArr_temp:array =NewArray ();6 for(vari = 0; I < arr.length;i++ ){7 for(varj = 1; J < Arr[0].length; J + + ){8ARR_TEMP[J-1] =Arr[i][j];9 }TenArr_new[i] =arr_temp; OneArr_temp =NewArray (); A } - returnarr_new; -}
Note: If you define only a new array, the following is the case. There will also be an error:typeerror:error #1010: The term is not defined and has no attributes.
So in the future when the two-dimensional array to operate, pay attention to this problem.
1 //In addition to the first column, the rest of the content2 functionF_arr (Arr:array)3 {4 varArr_new:array =NewArray ();5 6 for(vari = 0; I < arr.length;i++ ){7 for(varj = 1; J < Arr[0].length; J + + ){8ARR_NEW[I][J-1] =Arr[i][j];9 }Ten One } A returnarr_new; -}
2017/3/29_ Array Loop traversal problems