js array string includes
if (new RegExp(substrings.join("|")).test(string)) {
// At least one match
}
js array string includes
if (new RegExp(substrings.join("|")).test(string)) {
// At least one match
}
if Array includes string
function droids(arr) {
result = "These are not the droids you're looking for."
for (str of arr) {
if (str == 'Droids')
result = "Found Droids!"
}
return result;
}
if array includes string
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');
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us