Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to compare every element in array to a value

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If i understand that you want, try something like this

let values = [1, 2, 3, 123]

if (values.includes(123)) {
   *do some code*
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading