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

191
Vistas
Why am I unable to change the contents of this array

I am writing a test using jest, where I am retrieveing a 10x10 grid from my class. I want to loop over the array which contains this grid, and switch the status from true to 'hit' where the name of the grid is 'battleship1'.

let grid = battleships.returnGrid()
for (let i = 0; i < 10; i++) {
    for (let y = 0; y < 10; y++) {
        if (grid[i][y].shipName == 'battleship1') {
            console.log(grid[i][y].square)
            grid[i][y].status == 'hit'
        }
    }
}
console.log(grid)

This is the code which I am running. After running the for loop, and logging the grid, it is still in the original form, with the status of the grid being set to true.

Why am I unable to change the status to 'hit'?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are comparing and not setting:

grid[i][y].status == 'hit'

When you assign a value, just use it like this (only one =):

grid[i][y].status = 'hit'
about 4 years ago · Juan Pablo Isaza Denunciar

0

Have you tried changing operators a bit?

let grid = battleships.returnGrid()
for (let i = 0; i < 10; i++) {
    for (let y = 0; y < 10; y++) {
        if (grid[i][y].shipName === 'battleship1') {
            console.log(grid[i][y].square)
            grid[i][y].status = 'hit'
        }
    }
}
console.log(grid)
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