首頁  >  工具  > $.inArray(val,arr,[from])

返回值:NumberjQuery.inArray(value,array,[fromIndex])

jQuery $.inArray() 方法 概述

確定第一個參數(shù)在數(shù)組中的位置,從0開始計數(shù)(如果沒有找到則返回 -1 )。

參數(shù)

value,array,[fromIndex]Any,Array,NumberV1.2

value:用于在數(shù)組中查找是否存在

array:待處理數(shù)組。

fromIndex:用來搜索數(shù)組隊列,默認(rèn)值為0。

arrayArray

待處理數(shù)組。

示例

描述:

查看對應(yīng)元素的位置

jQuery 代碼:
var arr = [ 4, "Pete", 8, "John" ];
jQuery.inArray("John", arr);  //3
jQuery.inArray(4, arr);  //0
jQuery.inArray("David", arr);  //-1
jQuery.inArray("Pete", arr, 2);  //-1