Created
July 16, 2014 11:44
-
-
Save aisin/719c296c8ab8dfde1f29 to your computer and use it in GitHub Desktop.
jQuery判断指定元素是否存在和删除数组中指定元素
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************************** | |
* | |
* 判断指定元素是否存在 | |
* | |
* *********************************/ | |
var arr = ['a','b','c','d','e','f'] | |
var str = 'b'; | |
console.log( $.inArray(str , arr) ); | |
//结果: | |
1 | |
//说明:$.inArray(str , arr) 返回 str 在数组中的索引值,如果不存在返回 -1 | |
/*********************************** | |
* | |
* 删除数组中指定元素 | |
* | |
* *********************************/ | |
var arr = ['a','b','c','d','e','f'] | |
arr.splice($.inArray('c' , arr),1); | |
console.log( arr ); | |
//结果: | |
['a','b','d','e','f'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment