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

117
Visualizações
Set two-dimensional array value as property of object javascript

I have the following class: I am trying to set the value of this.grid[0][0] to 0, however when I run the following code I get the output in the console:

this.grid = 0: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
1: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
2: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
3: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
4: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
5: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
6: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
7: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
8: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
9: (10) [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]

class Pane {
  turnChance = 0.4;
  maxLength = 100;
  gridMultiplier = 20;
  constructor({
    height,
    width,
    p,
    start
  } = {}) {
    this.height = height;
    this.width = width;
    this.start = start;
    this.grid;
    this.initGrid();
  }
  initGrid() {
    this.grid = Array(this.width).fill(Array(this.height).fill(1));
  }
  generateLines() {
    this.grid[0][0] = 0;
  }
}
const pane = new Pane({
  height: 10,
  width: 10,
  start: [0, 0]
});
console.log(pane.grid)
pane.generateLines()
console.log(pane.grid)

Why is this happening, and how can I set this.grid[0][0] solely, without it affecting any other elements in the array?

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