how to Check if an array contains a string
var myList=["a", "b", "c"];
mylist.includes("d")//returns true or falseconst myArray: number[] = [2, 4, 6, 8, 10, 12, 14, 16];
const elements: number[] = [4, 8, 12, 16];
function containsAll(arr: number[]) {
return (
arr.includes(elements[0]) &&
arr.includes(elements[1]) &&
arr.includes(elements[2]) &&
arr.includes(elements[3])
);
}
console.log(containsAll(myArray));
or you could use the following line:
function c2(arr: number[]) {
return elements.every((val: number) => arr.includes(val));
}// To check if an array contains a string
const colors = ['red', 'green', 'blue'];
const result = colors.includes('red');
console.log(result); // true
// Or
const colors = ['Red', 'GREEN', 'Blue'];
const result = colors.map(e => e.toLocaleLowerCase())
.includes('green');
console.log(result); // true
Also in JavaScript:
- testing a function in jest on click react
- react native onChangeText resize the background image
- input show validation message
- javascript resize image base64
- nodejs hashing
- how to run js before submit html
- input output ionic
- angular get current route
- debugger js
- Javascript remove array item by value
- ternary operator javascript
- reactjs start
- Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
- change span value javascript
- check when input number value goes up or down
- for each python json
- convert date time to string javascript
- connect mongo to express api
- react callback set staet
- remove react native cli mac
- socket io query
- $.fn.dataTable.tables in container
- react native sovrapporre immagini
- javascript get data attribute value