我知道之前已经问过这个问题,但我找不到解决方法...... 我只是这样做:
var tagsToUse = [];
var refTags = firebase.database().ref('/tag/');
refTags.once('value', function(tags){
pois.forEach(p=>{
tags.forEach(function(t){
if(p.tag == t.key){
console.log("Index " + tagsToUse.indexOf(t.child('name').val()))
if(tagsToUse.indexOf(t.child('name').val())==-1){o
tagsToUse.push(t.child('name').val())
console.log("Added "+ t.child('name').val())
}
}
return false;
})
})
})
它不断添加重复项,Index
打印始终为-1,即使名称已在数组中。最后我有一个重复的数组。这有什么问题?为什么打印-1?