JS Array find & findIndex


Array find() Method

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var ages = [10, 23, 19, 20];
	document.write(ages + "<br>");
	
	var b = ages.find(checkAdult);
	document.write(b + "<br>");

	function checkAdult(age) {
		return age >= 18;
	}
  </script>
</head>
<body>
</body>
</html>


Array findIndex() Method

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var ages = [10, 12, 23, 20];
	document.write(ages + "<br><br>");
	
	var b = ages.findIndex(checkAdult);
	document.write(b + "<br>");

	function checkAdult(age) {
			return age >= 18;
		}
  </script>
</head>
<body>
</body>
</html>