1

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

2 Answers 2

3

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`)
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.