I’m trying to sort through an array for artists that lived through the twentieth century. The numbers in the year property of the array are strings rather than numbers:
"years" : "1471 - 1528"
So I’m trying to split all the years, convert them to numbers, then compare the numbers that way. But when I log to console, I get an error that says “array[i].split is not a function”. I’ve tried array.years.split(" ")
and gotten an error as well. I’m just learning JS so bear with me if it’s an obvious mistake, but can anyone tell me what I’m doing wrong?
function get20s (array) {
const newArray = [];
for (let i = 0; i < array.length; i++) {
const splitYears = array[i].split(" ");
splitYears.splice("-")
Math.floor(splitYears);
if (splitYears[0] > 1900 && splitYears[1] < 2000) {
return newArray.push(array[i].name);
}
}
return newArray;
}