I am struggling with how to check if an arry contains a value.
html:
var newprodata = [];
var alreadyUsedIds = [];
angular.forEach(prodata, function(line) {
if(line.name === proName || line.brand === proBrand){
//if (line.id === 183) {
var id = parseInt(line.id);
console.log("line.id",id);
console.log("alreadyUsedIds",alreadyUsedIds);
console.log( "alreadyUsedIds.indexOf("+id+")", alreadyUsedIds.indexOf(id) );
//}
if (alreadyUsedIds.indexOf(id) > -1){
console.log("on record pas");
} else {
//console.log("line.id",line.id);
console.log("on record");
alreadyUsedIds.push(parseInt(id));
newprodata.push(line);
}
}
});
here's my console output
:
alreadyUsedIds [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
0: 24
1: 25
2: 26
3: 27
4: 28
5: 29
6: 30
7: 31
8: 32
9: 33
10: 34
11: 35
12: 36
13: 183
length: 14__proto__: Array[0] filters.js:46
alreadyUsedIds.indexOf(183) -1
, it should not be '-1' because '183' is in the array !!!
Moreover, if I set a breakpoint, and check manually I get: alreadyUsedIds.indexOf(183) = 13