Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!