I have the following code snippet.
$scope.functionName = function(id) {
var flag = true;
var numbers = [1, 3, 30];
for (var i = 0; i < numbers.length; i++) {
if (id == numbers[i]) {
flag = false;
} else {
flag = true;
}
}
if (flag == true) {
console.log("this is true");
}
if (flag == false) {
console.log("this is true");
}
}
What I want to perform is, if the input value is in the array, flag value should be false and if not it should be true. But, in this code snippet although flow goes inside the for loop after that it doesn't go to any of the if conditions. After entering the for loop it directly outputs "this is true". flag is always being true.
"true"and"false"instead oftrueandfalse?$scope.functionName = function(id){ return [1,3,30].includes(id)}console.logstatements say "this is true".