“Wenn Saiten in Array” Code-Antworten

Wenn das Array String enthält

function droids(arr) {
  let result = 'These are not the droids you\'re looking for';
  for(let i=0; i<arr.length;i++) {
      if (arr[i] === 'Droids') {
      result = 'Found Droid';
    }
  }
  return result;
}

// Uncomment these to check your work! 
const starWars = ["Luke", "Finn", "Rey", "Kylo", "Droids"]
const thrones = ["Jon", "Danny", "Tyrion", "The Mountain", "Cersei"]
console.log(droids(starWars)) // should log: "Found Droids!"
console.log(droids(thrones)) // should log: "These are not the droi





//A simpler approach 

console.log(starWars.includes('Droids') ? 'Droid Found' : 'These are not the droids you\'re looking for');
console.log(thrones.includes('Droids') ? 'Droid Found' : 'These are not the droids you\'re looking for');
Energetic Eel

Wenn Saiten in Array

if (['', 'Choose an option'].includes(value)) {
Surf Kid Bonanza

Ähnliche Antworten wie “Wenn Saiten in Array”

Fragen ähnlich wie “Wenn Saiten in Array”

Weitere verwandte Antworten zu “Wenn Saiten in Array” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen