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

84
Views
Javascript circular object array when assigning object to more than one array element

Could someone please explain why this doesn't work and populates the array with "circular object Array"s when there are no circular references? I know there are a million ways to do this better, and I do not plan on using this code, but I really want to know why it doesn't work. I know it must have something to do with how JS passes references, but am confused on what limit we are hitting here.

 const sub = [{1: 2}, {3: 4}, {5: 6}]
const sub2 = [{7: 8}, {9: 0}, {11: 12}]
const sub3 = [{12: 13}, {14: 15}, {16: 17}]
const o = [ {label: 'a', submenu: sub}, {label: 'b', submenu: sub2} ]
console.log(o)
    
o.forEach((currentValue, index, arr) => {currentValue.click = sub3})
    
console.log(o)

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