I am trying to write a function that only returns the numbers in an array.
The error message is telling me that the properties of ‘1’ cannot be read in the test array in the function call, but I don’t know why that is.
Can anyone help please?
"use strict";
function filter_list(l) {
const result = [];
let i;
for (i = 0; i < l.length; i++)
if (typeof l[i] === "number") {
result.push.l[i];
}
return result;
}
console.log(filter_list(["john", 1, "peter", "dave"]));
I think you’re right about the brackets, but I must be missing something when it comes to pushing an array item into another array (as opposed to an individual string, number etc…)