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

279
Visualizações
Empty array, which when expanded have objects, after POST fetch

I'm making the 2024 game with the Hexes and I have a RNG server, which gives me the random coordinates and values for new blocks whenever button is clicked. The problem is that, when I make and POST fetch for this data and I remove the promise, I end up with an array, which does not exactly work as one.This is how it looks in console.

The code is

  let cellsValueArray = [];
  
  async function callAsync(radius, cellsWithValue=[]) {
    let startGameCells = [];
    let filledCells = startGameCells.concat(cellsWithValue);
    let rawResponse = await fetch(`http://localhost:13337/${radius}`, {
      method: 'POST',
      mode: 'cors',
      body: JSON.stringify(filledCells),
    })
    let content = await rawResponse.json();
    cellsValueArray.push.apply(cellsValueArray, content);
  };
  callAsync(radius);

I want to have an ability to do stuff with this array like array.x array.y array.value, to change the value of hex objects on the DOM. I tried array[0].x, which sometimes works, but the return Error( cannot assign methods to undefined). So array[0] returns undefined.

about 4 years ago · Juan Pablo Isaza
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