How do I check whether an array contains a string in TypeScript?
var array: Array<string> = ['one', 'two', 'abc'];
The same as in JavaScript, using Array.prototype.indexOf():
console.log(array.indexOf('abc') > -1);
Or using ECMAScript 2016 Array.prototype.includes():
console.log(array.includes('abc'));
However, you wouldn’t usually do that for a string array, but rather for an array of objects. There those methods were more sensible. For example
const arr = [{foo: 'bar'}, {foo: 'bar'}, {foo: 'baz'}];
console.log(arr.find(e => e.foo === 'bar')); // {foo: 'bar'} (first match)
console.log(arr.some(e => e.foo === 'bar')); // true
console.log(arr.filter(e => e.foo === 'bar')); // [{foo: 'bar'}, {foo: 'bar'}]
References: