Home > Software engineering >  How to use forEach to check if there is a match in the array (JavaScript)
How to use forEach to check if there is a match in the array (JavaScript)

Time:06-09

How to use forEach to check if there is a match in the array (JavaScript)

CodePudding user response:

I'm not sure exactly what you're asking; how do you "log out" variables in code?

In general, you don't need a loop to check existence an array; that's what the Array.includes method is for:

if (files.includes(upload.type)) {
    console.log("type is OK")
} else {
    console.log(`type ${upload.type} not found`)
}

CodePudding user response:

const isMatch = files.some((type) => upload.type === type);

  • Related