javascript - Compare array js -


this question has answer here:

i have following

var = [4,6,12]; var b = [4,6];  (var = 0; < a.length; i++) {     (var j = 0; j < b.length; j++) {        if (a[i] !== b[j]) {          a.pop();        }     } } 

i want compare 2 , remove 12 if not found in b. not want create new array result remove a.

however, if console log empty.

the reason why a coming out empty because of double loop. you're comparing each element of a every other element of b. when hit a[0] == b[1], obviously, 4 != 6 pop it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -