codecamp

jQuery.inArray(val,arr,[from])

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

概述

确定第一个参数在数组中的位置,从0开始计数(如果没有找到则返回 -1 )。

参数

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

value:用于在数组中查找是否存在

array:待处理数组。

fromIndex:用来搜索数组队列,默认值为0。

arrayArray

待处理数组。

示例

描述:

查看对应元素的位置

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
jQuery.map(array, callback)
jQuery.support
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }