What I essantily want to do is compare all values in array to 123 in an if statment
let values = [1, 2, 3, 123]
if (123 == values.forEach(e => {return e})){
currently, I'm getting an error:
values.forEach(e => {return e})) is not a function
What I essantily want to do is compare all values in array to 123 in an if statment
let values = [1, 2, 3, 123]
if (123 == values.forEach(e => {return e})){
currently, I'm getting an error:
values.forEach(e => {return e})) is not a function
If i understand that you want, try something like this
let values = [1, 2, 3, 123]
if (values.includes(123)) {
*do some code*
}
const array1 = [1,2,123,123];
array1.forEach(element => element === 123 && console.log(element));
You can use array.indexOf() function to check whether 123 is present in the array or not :
let values = [1, 2, 3, 123]
if (values.indexOf(123)!=-1) {
...write code
}
let values = [1, 2, 3, 123]
if (values.indexOf(123)!=-1) {
console.log("123 is present");
}else {
console.log("123 is not present");
}