I wanted to compare two array and store the element that is present in both array into a new array. So I write this code but it didn't work.
var sampleArray = [1, 2, 3, 4, 5, 6, 7];
var sampleArray2 = [5, 6, 7, 8, 9, 10 ,11];
var similarElements =[];
for (let i = 0; i < sampleArray.length; i++) {
for (let j = 0; j < sampleArray2.length; j++) {
if (sampleArray[i] === sampleArray2[j]) {
similarElements.push();
}
}
}
console.log(similarElements);