骑驴找蚂蚁

全干工程师

typescript、javascript判断内容是否在数组中?

如:  

var channelArray: Array = ['one', 'two', 'three'];

 

使用Array.prototype.indexOf():

console.log(channelArray.indexOf('three') > -1);

在ES2016中Array.prototype.includes():

console.log(channelArray.includes('three'));

 

 

留言