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

293
Vistas
why splice remove a data in array from all variable?

I am currently learning javascript, i create an array and then define it in 2 variable arrayBase and arrayData but when i use splice, all the data in other variable also get removed. I don't know what happen

const arr=[1,2,3,4,5]
const arrayBase=arr
let max=0
let min=0
let arrayData=arr

for(let i = 0; i<arrayBase.length;i++){
    console.log(i,arrayBase)
    let x
    arrayData.splice(i,1)
    arrayData.forEach((item)=>x=x+item)

    if(x>max){
        max=x
    }
    if(min<x){
        min=x
    }
    arrayDataabc=arr
 }

Can anyone help explain why splice make other variable array get removed? Thanks before!

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

0

In Javasxript Objects (even arrays are object) are mutable means it can be modified .

when you assign the objects (even array) to the new variable , the new variables point to the same objects.

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