I tried something like:
var diff = $(array1).not(array2).get();
console.log(diff); // store the difference
And replace .not()
with .is()
but that didn't work..which generated an error. It only stored the difference, but I want only the same values stored in a new array. How do I do that in jQuery regardless if it's length size in both arrays?
var array1 = ['a','b','c','d','e','f','g'];
var array2 = ['c', 'b'];
var sameValArr = [];
// TODO:
// 1. compare the two arrays if there's any matching values in both
// 2. if yes, store the matching value in a new array; if no, do nothing
// 3. check the new array if it isn't empty
// 4. if empty, hide the video; if not empty do nothing (show video)
for(var i = 0; i < array1.length; i++)
{
for(var j = 0; j < array2.length; j++)
{
if(array1.indexOf([i]) === array2.indexOf([j]))
{
sameValArr.push(array1[i]);
console.log("sameValArr: ", sameValArr);
}
}
}
The answer provided to this question using indexOf()
method didn't work.