How to check if the value exists in array?

PHOTO EMBED

Wed Feb 08 2023 19:38:54 GMT+0000 (Coordinated Universal Time)

Saved by @chesterheng #javascript

const army=["Marcos", "DeltaForce", "Seals", "SWAT", "HeadHunters"];  

if(army.indexOf("DeltaForce") !== -1) {
  console.log("exist")
} else {
  console.log("not exist")
}

if(army.includes("DeltaForce")) {
  console.log("exist")
} else {
  console.log("not exist")
}

for(let i = 0; i < army.length; i++) {
  if(army[i] === "DeltaForce") {
    console.log("exist")
    break
  }
}
content_copyCOPY