<!DOCTYPE html>
<html>
<body>
<p>Click the button to check get the value of the first element in the array that has a value of 18 or more.</p>
<button onclick="returnAdults()">Try it</button>
<p id="demo"></p>
<script>
demo = document.getElementById("demo");
var peopleList = [
{
name: "Joe",
age: 3
},
{
name: "Sara",
age: 10
},
{
name: "Luis",
age: 18
},
{
name: "Franzi",
age: 20
}
];
const adultsList = peopleList.filter((people)=>{
return people.age >= 10;
})
function printAdultList(person, index) {
demo.innerHTML += "index[" + index + "]: " + person.name + " " + person.age + "<br>";
}
function returnAdults() {
return adultsList.forEach(printAdultList);
}
</script>