Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

0

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda