Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0') -- when all objects are not-undefined

Working on data visualization with d3.js. I'm quite a novice in javascript, but I come here trying to get to the root of my issue.

I'm trying to plot some movie-based data, in which every data point is the string data type. Therefore, I have to convert dates to the Date data type, and Movie Ratings to Number or Float data type for d3 to plot the data properly, else there's an error.

Pretty much, the data is stored in an array, which holds 11 other arrays, one for each movie critic, in which each movie critic array holds 237 objects for each movie watched that year, in which each object looks like

    {
    "key": "Derek",
    "Date": "2019-01-25T05:00:00.000Z",
    "value": 5,
    "Movie": "The Butterfly Effect",
    "Pickedby": "Dan"
} 

Where key is the movie critic, and Pickedby is the person who picked the movie.

Here is the code I'm using to convert a date like 1/25/2019 into "2019-01-25T05:00:00.000Z" and am trying to convert the value item (from a string) into a Number, or Floating Point Number. (Some ratings can be like 3.5, 6.5, etc.)

for (let j = 0; j < series.length; j++) {
    for (let i = 0; i <series[j].length; i++){

      series[j][i].Date = new Date(series[j][i].Date)
      series[j][i].value = Number(series[i][j].value)
    
    }
}

The date conversion line of code works as expected. However, converting the value item into a Number or Float is causing Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0') error to arise.

The thing is, all of the value items data through the entire array is a string. There isn't an undefined issue. Sure, some values are (x's) or some other alphabetical character, but that should be converted to NaN at least, and it is for some.

Any thoughts on why this error could be arising, given the information I have provided? I can always probably provide more detail.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like a typo was made in the code, where you are not accessing the correct value in the cast to Number.

Instead of:

series[j][i].value = Number(series[i][j].value)

it should be:

series[j][i].value = Number(series[j][i].value)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda