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

144
Views
Is it possible to have multiple keys point to the same object?

Basically I want to call myList[i] and get the same value for i = 1, 2, 3, 4 then a second value for 5, 6, 7, 8 and so on. I don't really want to copy-paste the value for 1 into 2, 3, 4.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use an array of objects

const arr = [...Array(4).fill({ value: 1 }), ...Array(4).fill({ value: 3 })];

console.log(arr[0].value);
console.log(arr[2].value);
console.log(arr[4].value);
console.log(arr[6].value);
arr[0].value = 2;
console.log(arr[0].value);
console.log(arr[2].value);
console.log(arr[4].value);
console.log(arr[6].value);

Each element is a reference to the same object.

That's not possible with an array of primitives.

about 4 years ago · Juan Pablo Isaza Report

0

You can try using this -

myList[Math.floor((i-1)/4)]

where i = 1, 2, 3, 4 ...

But if i starts from 0, then

myList[Math.floor(i/4)]

Adjust the +/- 1 according to your requirements.

Where 4 is the block size to which you need to divide the array with.

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!