I am having trouble with some basic javascript. I want this function to return an array of all objects within the given array that have the name "Ray" assigned to name. I can't get the push part to work.
const people = [{name: "Jack", age: 30}, {name: "Ray", age: 32}, {name: "Anna", age: 28}];
function findRay(arr) {
let response = [];
for(let i = 0; i < arr.length; i++) {
if(arr[i].name === "Ray") {
response.push(arr[i]);
}
}
return response;
}
console.log(findRay(people));