Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
array[i].(split) is not a function

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? Here's a part of the array:

const artists = [
  { "name": "artist name", "years": "1884 - 1920"} ,
...
]

function getYears (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;
}
console.log(getYears(artists));
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm only guessing because you aren't showing the full content of the array, but I suspect you want something closer to:

array[i].year.split(" ")

Further, rather that split on the spaces, it would make more sense to split on the spaces and the dash together, using a regex that doesn't care about how many spaces (if any) are present:

array[i].year.split(/\s*-\s*/)

The above will return a single-element array when there is one year, a two-element array when a range of years is given.

One further step would be to convert the array to numbers instead of strings:

array[i].year.split(/\s*-\s*/).map(n => parseInt(n, 10))

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda