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

骑驴找蚂蚁 · 2020-07-14

如:  

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

 

使用Array.prototype.indexOf():

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

在ES2016中Array.prototype.includes():

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

 

 

全栈工程师

321 浏览
0