• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

186
Views
Issue when trying to splice an element from array

const data = response.data
console.log(data) let tmp = data.groups_with_selected[7]; 
data.groups_with_selected.splice(7, 2);
data.groups_with_selected.splice(2, 0, tmp);

I am trying to splice an element from an array from 7th position, and then insert into 2nd position. But during that process I am successfully able to change the 7th position to 2nd. but issue is after changing the position 7 or 8th position is reflecting in the array.

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

0

you can do it like that: you should choose the first element of the array which produced by splice by default to become an item and not an array, then insert it to your array at a certain position;

const temp = data.groups_with_selected.splice(7,1)[0]
 data.groups_with_selected.splice(2,0,temp )

so it will insert the 8th element in the third position;

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error