Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  130] [ 3]  / answers: 1 / hits: 5680  / 11 Years ago, mon, december 16, 2013, 12:00:00

I'd like to check which elements are equal in my two arrays, but can't get it working.

This is my code:



for (var i; i < bombs.length; i++) {
for (var j; j < bombsDb.length; j++) {
if (bombs[i].name === bombsDb[j].address) {
console.log(bombs[i].name);
} else {
console.log(non-equal elements);
}
}
}


So the first array contains objects from the google places api and the second one contains data from my database.

Thanks in advance!


More From » jquery

 Answers
3

You have to initialize i and j;



   for (var i = 0; i < bombs.length; i++) {
for (var j = 0; j < bombsDb.length; j++) {
if (bombs[i].name === bombsDb[j].address) {
console.log(bombs[i].name);
} else {
console.log(non-equal elements);
}
}
}

[#49493] Sunday, December 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;