boo*_*ans -1 javascript arrays jquery google-places-api
我想检查我的两个数组中哪些元素相同,但无法使其正常工作.
这是我的代码:
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,第一个数组包含来自google places api的对象,第二个数组包含来自我的数据库的数据.
提前致谢!
你必须初始化i和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");
}
}
}
Run Code Online (Sandbox Code Playgroud)