PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > JavaScript教程 > 正文

    js搜索指定的Object,并返回第一个匹配项从零开始的索引

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:/**方法:Array.IndexOf(obj)*功能:搜索指定的Object,并返回第一个匹配项从零开始的索引*参数:要查找的Object对象*返回:找到返回该元素在数...

    1. /* 
    2.  * 方法:Array.IndexOf(obj) 
    3.  * 功能:搜索指定的Object,并返回第一个匹配项从零开始的索引 
    4.  * 参数:要查找的Object对象 
    5.  * 返回:找到返回该元素在数组中的索引,否则返回-1 
    6.  */ 
    7. Array.prototype.IndexOf = function(obj) { 
    8.         if (null == obj) { 
    9.             return
    10.         } { 
    11.             for (var i = 0, n = 0; i < this.length; i++) { 
    12.                 if (this[i] == obj) { 
    13.                     return i; 
    14.                 } 
    15.             } 
    16.         } 
    17.  
    18.         return -1; 
    19.     } 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-69-3109-1.html
    相关热词搜索: