I would like to create a function as simple as possible that it receives an Array of Person objects (example format: {name: "Alex",age: 24}
) that returns a new array only with Person objects that are aged between 20 and 30 years.
My code is this:
var pessoa = [{
nome: 'Diego',
age: 17,
},
{
nome: 'Natalia',
age: 12,
},
{
nome: 'David',
age: 27,
},
{
nome: 'Daniel',
age: 30,
},
];
function idade(pessoa) {
if (age => 20 && <= 30) {
(a partir daqui nao sei como fazer)
}
}
I do not know if the code is right, I want some help on how to do it.