jQuery | grep() Method (ok)
https://www.geeksforgeeks.org/jquery-grep-method/
Phương thức grep () này trong jQuery được sử dụng để tìm các phần tử của một mảng thỏa mãn hàm lọc.
jQuery.grep(array, function(element, index) [, invert])<!DOCTYPE html>
<html>
<head>
<title>
JQuery | grep() method
</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p id="GFG_UP" style="font-size: 20px; font-weight: bold">
</p>
<button onclick="GFG_Fun();">
click here
</button>
<p id="GFG_DOWN" style="font-size: 26px;
font-weight: bold; color: green;">
</p>
<script>
var up = document.getElementById('GFG_UP');
var down = document.getElementById('GFG_DOWN');
var arr = [1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1 ];
up.innerHTML = "Click on the button to " +
"perform the operation.<br>" +
"Array - <br>[" + arr + "]";
function GFG_Fun() {
var d = $.grep(arr, function(n, i) {
return (n !== 7 && i > 4);
});
down.innerHTML = JSON.stringify(d);
}
</script>
</body>
</html>Last updated
Was this helpful?