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

151
Vistas
array data changed without manipulation

I face an behavior which I cant explain but reproduce. I created an array of objects as a source data. I declared an second array and passing the data from the first. Now I can manipulate the second array without losing the original data.

But as soon as I manipulate the second array the source array changed too.

Please refer to the console output.

  • The first console.log(person) before maniupulation of filterPerson (expected output ok).
  • The second console.log(person) after maniupulation of filterPerson (expected output not ok) Since I did not adressed the first array those data shouldn´t be touched at all.

Can somebody explain me this?

var person = [{"name": "Abby", "age": "22"}, {"name": "Paul", "age": "28"}, {"name": "Susi", "age": "19"} ]
var filterPerson = []

filterPerson = person

console.log(person)

for (var element of filterPerson) {
    if (element.age != 22) {
        element.age = 18
  }
}

console.log(person)

console.log(filterPerson)

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