Skip to content Skip to sidebar Skip to footer

Delete Elements From Array Javascript

Maybe by title seems a easy question, but I didn´t know how to do the shortest title for my question. I want to delete elements from array on javascript, yes, but what I am lookin

Solution 1:

var C = [];
for(var i = 0; i < B.length; i ++){
    if(A.indexOf(B[i]) > -1){
        C.push(B[i]);
    }
}

What this does is

  1. Creates array C
  2. Runs through each item in B
  3. if B[i] is in A, add it to C

Post a Comment for "Delete Elements From Array Javascript"