Skip to content
Advertisement

How to get every element in an array in an if statement js [closed]

So I’m trying to check names through an array and I don’t want to have to use

if (<array name>[0,1,2,3,4,5,6,7]) 
      { code in here }

Advertisement

Answer

depend on what you are trying to do u can use forEach or map

let arr = [1,2,3,4,5,6,7,8,9,10];


arr.forEach((item)=>{
console.log(`${item} is greater than 5 : ${item>5}`)
})
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement