-4

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 }
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
  • 2
    What exactly are you trying to check? – Sebastian Simon Apr 02 '21 at 00:40
  • `name == names[0,3]` is exactly the same as `name == names[3]`. Look up [`includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) and [`slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). Familiarize yourself with [how to access and process nested objects, arrays or JSON](https://stackoverflow.com/q/11922383/4642212) and use the available [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Static_methods) methods (both static and on prototype). – Sebastian Simon Apr 02 '21 at 03:36

1 Answers1

0

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}`)
})
ucup
  • 665
  • 6
  • 17