Javascript - Do something when an element in two arrays are the same? -
i found solution returned array of elements without duplicates:
array1 = array1.filter(function(val) { return array2.indexof(val) == -1; });
however, want modify code little bit. instead of being returned array without duplicates, want when there duplicate. problem is, i'm not sure how code works. thing i'm not sure how val
gets set, or is.
for (var = 0; < json.length; i++) { var item = json[i]; // if json.indexof(val?), }
read docs array filter
method then. val
parameter of callback passed single array items, i.e. json[i]
or item
in case:
for (var = 0; < json.length; i++) { var item = json[i]; if (json.indexof(item) >= 0) { // } }
Comments
Post a Comment