在kotlin語言中的數(shù)組有一個(gè)contains函數(shù)非常方便徊哑,然后就想在js中實(shí)現(xiàn)
// kotlin
val keyword = arrayOf("function","var","return")
if(keyword.contains("var"))
{
//....
}
//JavaScript
Array.prototype.contains = function(element)
{
for(var i in this)
{
if(this[i] === element)
{
return true;
}
}
return false;
}
var keyword = ["==",">=","<="];
keyword.contains("==")