if array includes string

Solutions on MaxInterview for if array includes string by the best coders in the world

showing results for - "if array includes string"
Pierre
28 Oct 2019
1if (new RegExp(substrings.join("|")).test(string)) {
2    // At least one match
3}
4
Valeria
02 May 2016
1function droids(arr) {
2  let result = 'These are not the droids you\'re looking for';
3  for(let i=0; i<arr.length;i++) {
4      if (arr[i] === 'Droids') {
5      result = 'Found Droid';
6    }
7  }
8  return result;
9}
10
11// Uncomment these to check your work! 
12const starWars = ["Luke", "Finn", "Rey", "Kylo", "Droids"]
13const thrones = ["Jon", "Danny", "Tyrion", "The Mountain", "Cersei"]
14console.log(droids(starWars)) // should log: "Found Droids!"
15console.log(droids(thrones)) // should log: "These are not the droi
16
17
18
19
20
21//A simpler approach 
22
23console.log(starWars.includes('Droids') ? 'Droid Found' : 'These are not the droids you\'re looking for');
24console.log(thrones.includes('Droids') ? 'Droid Found' : 'These are not the droids you\'re looking for');
Montserrat
21 Mar 2020
1function droids(arr) {
2    result = "These are not the droids you're looking for." 
3    
4    for (str of arr) {
5        if (str == 'Droids')
6            result = "Found Droids!"
7    }
8    
9    return result;
10}
11
queries leading to this page
array contains from arrayjs string contains value from arrayarray includes in javascriptjavascript includes any string in this arrayarray contains string jsarray contains a stringjs if string in arrayjs string includes any of arrayhow to check if array contains a string in javascriptstring contains array of strings javascriptstring includes array javascriptarray contains stringstring included in array jsfind element who contains string in array javascripthow to check if array contain string jsuse include method in array in javascriptcheck string contains array javascriptcheck if array of string contains element in array of stringjavascript array includes examplejavascript see if string is in arraycheck if array contains string jsstring contains array of stringincludes array javascript methodjs includes array of stringsdoes array contain stringjavascript contains string in arrayif array contains stringjs includes astring arrayverify if string is in arraycheck if array includes string jsarray string contains methodstring array includesarray includes methodjavascript includes array of stringsstring includes array values javascript node check if array contains stringif array contains string javascriptstring array containarray includesif string in array jsarray string contains javascriptjs array functinscheck array its includes stringarray includes in jsstring contains in array jsif array include stringif string array contains javascriptjavascript array includes stringstring that contains arrayjavascript string includes any string in arrayif string contains from arraystring includes in array javascriptnodejs array contains stringstring array contains in javascriptarray of string contains jscheck if array contains string javascriptjavascript aray includescontainsjs is string in arrayjavascript string array containsjavascript return array contains some stringincludes text arraystring array contains jsincludes javascript arrayjs if array item included in stringarray contain string js array of strings containsfind item in array that contains string javascriptjs array contain stringjavascript string contains from arraycontains in array javascriptjs string in arrayincludes in javascript array and stringcheck if string is in array javascripthow to turn string that contains and array into an array jsincludes work with string and array 3farray includes strings javascriptjs array includeincludes array of string jsjavascript array include an stringjavascript array includes string likejavascript check if string contains any of arraycheck if string in array javascripthow to find the string contain the array in jsincludes function array javascriptincludes to check arraycheck if a string is in array javascriptcheck if array includes stringjavascript array of string containscheck string includes in javascript by arrayif array includes a stringjs check if string contains any string in arraycheck if array contatin string and return this stringjs check if str in arraycontain string array javascriparray element contains string javascriptjs array contains stringnode js check if array contains stringjavascript array contains stringcheck if array includes a text jscheck if string in array jsarray include string javascriptjavascript find if array contains stringcheck if string is in arrayjavascript string contains substring from arrayif string ontains arrayif string array containsis includes work with arrayincludes anything array jsstring include some element from array javascriptcheck if array of string contains element like in array of stringincludes example in arraystring contain in array jsstring includes any item in array of string javascriptarray includes string javascriptcheck if array includes a stringif array includes string javascriptincludes in javascript arrayjavascript array of strings get string that containsreturn string array contains javascriptif string in arrayis string contain any ellement from arrayincludes arraycheck if string contains array of strings jsif array includes stringcheck if string contains in array of stringsstring includes array string javascriptjavascript get array element contains stringif array value contains stringstring array containsincludes in array javascriptincludes in arrayjs string contains any of arrayarray includes in javascriptjavascript include array stringcheck array if includes textjs string includes one of arrayincludes for array of stringstring includes some array elements javascriptcheck if string is in array of strings jsstring contains in array javascriptarray contains string javascriptcheck if array contains stringhow to check if a string contains an array element in javascriptif array includes string