Problem analysis: The elements in the migration group can be divided into two cases,
1, do not operate the original array;
Do not manipulate the original array, you can create a new array, using the stack method of the array push, loop the elements in the array, the addition of a new array of elements that are not equal to a particular element.
function Remove (arr, item) {
var res=[];
for (Var i=0;i<arr.length;i++) {
if (Arr[i]==item) {continue}
else{
Res.push (Arr[i]);
}
}
return res;
}
2, the operation of the original array, you can take advantage of the operation of the array splice, note that the splice return value is the deleted item, at the same time, splice will change the length of the array, should be executed splice must perform I--。
function Removewithoutcopy (arr,item) {
for (Var i=0;i<arr.length;i++) {
if (Arr[i]==item) {
Arr.splice (i,1); i--;
}
}
return arr;
}
To move an element in an divisor group