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

129
Views
push some objects into array after some specific index using javascript

I am trying to implement a logic that, i want to push some objects into the array after a specic index like, In a array have 5 objects then , i want to push two new objects after 3 index in current array. How can i do it.

const currarr = [{id:1,name:"abc"},{id:2,name:"efg"},{id:3,name:"hij"},{id:4,name:"klm"},{id:5,name:"nop"}];

otherObj = [{id:6,name:"fdf"},{id:7,name:"gfg"}]

I want to push the two new objects of otherObj array into the currarr array after the 3 index.

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

0

curarr.splice(3, 0, ...otherObj)
about 4 years ago · Juan Pablo Isaza Report

0

With the splice method, you can add or delete elements from a specific index.

For more resources.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

const currarr = [{id:1,name:"abc"},{id:2,name:"efg"},{id:3,name:"hij"},{id:4,name:"klm"},{id:5,name:"nop"}];

const otherObj = [{id:6,name:"fdf"},{id:7,name:"gfg"}]


currarr.splice(3, 0, ...otherObj)

console.log(currarr)

about 4 years ago · Juan Pablo Isaza Report

0

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

for more checkout below links Mozila W3c

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!