Home > Web Front-end > JS Tutorial > body text

How to use the $.grep() utility function in jQuery to filter elements in an array

黄舟
Release: 2017-07-19 09:18:47
Original
1423 people have browsed it

How to use the $.grep() utility function in jQuery to filter elements in an array

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>使用$.grep()工具函数筛选数组中的元素</title>
<script src="../lib/jquery-2.0.3.min.js" type="text/javascript"></script>
<style type="text/css">
	body{font-size:13px}
	p{margin:5px;padding:10px;border:solid 1px #666;background-color:#666;width:300px;}
</style>
<script type="text/javascript">
	$(function(){
		var strTmp = "筛选前数据";
		var arrNum=[2,8,3,7,4,9,3,10,9,7,21];
		var arrGet = $.grep(arrNum,function(ele,index){
			return ele>5 && index<8;//元素值大于5且序号小于8
		});
		strTmp +=arrNum.join();
		strTmp +="<br/><br/>筛选后数据:";
		strTmp +=arrGet.join();
		$("#pTip").append(strTmp); 
	})
</script>
</head>
<body>
	<p id="pTip"></p>
</body>
</html>
Copy after login

The above is the detailed content of How to use the $.grep() utility function in jQuery to filter elements in an array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!