js判断字符串是否在数组中

先加一个扩展函数: 
Array.prototype.contains = function (obj) { 
var index = this.length; 
while (index–) { 
     if (this[index] === obj) { 
         return true; 
     } 

return false; 
}

定义一个数组: var arr_qf = ["原单价", "优惠折扣(%)", "月租金"];

调用函数,检测是否存在:  arr_qf.contains(‘日租金')

猜你喜欢

转载自www.cnblogs.com/heyiping/p/10616593.html