1. Filter return multiple array
2. find return single return item
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Diff b/w Filter and Find With example</title>
</head>
<body>
<input type="text" id="InputValue" name="InputValue">
<button onclick="checkFunc()">Click Here</button>
<script>
	function checkFunc() {
	    const newArray = [1,2,3,4,5,6,7,8,7,2,1,3,5,6,4,3,6,45,65,34,1,1,2,2];
		let InputValue = document.getElementById('InputValue').value;
		const filterValue = newArray.filter(v=>v==InputValue)
		const findValue = newArray.find(v=>v==InputValue)
		console.log(filterValue,findValue)
	}
</script>
</body>
</html>

 
 
 
 
No comments:
Post a Comment