js给系统对象(数组、字符串等)添加一个扩展函数

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

return false; 
}

定义一个数组: 
var arr_qf = [“jpg”, “png”, “gif”, “bmp”, “html” ,”jpeg”];

调用函数,检测是否存在: 
arr_qf.contains(‘html’)

原文地址:https://www.cnblogs.com/phpyangbo/p/15064756.html