I have a code like:
var data = ["apple", "ball", "cat", "dog", "elephant", "fish", "gorilla"]
var index = [1, 3] // ball and dog
var to = 5 // fish
for(var i in index){
console.log(index[i])
var local_data = data
data.splice(to, 0, data.splice(index[i]), 1)
}
console.log(data)
console.log(index)
Here var index = [1,3] is the index value of the data to be set.
What I want here is, to set the value of index i. e ball and dog after fish and the rest remains on the order.
After inserted I want the index value to be changed according to the new position of the ball and dog i. e [4, 5]
Updata
In the end I want the result like:
console.log(data) should give
["apple", "cat", "elephant", "fish", "ball", "dog", "gorilla"]
and console.log(index) should give:
[4, 5] // new value of ball and dog