JoshKisb
JoshKisb

Reputation: 752

Javascript method chaining on slice not working

I am trying to reorganize an array to use it in a for loop. I have tried slicing it then merging with sliced elements but i get the error

TypeError: images.slice(...).merge is not a function

Here is an example of what I am trying

var images = ["0", "1", "2", "3", "4", "5"];
var f_iamges = images.slice(2).merge(images.slice(0, 2))

console.log(f_iamges)

I expected output ["2", "3", "4", "5", "0", "1"] I also want the original copy to remain unchanged.

Upvotes: 0

Views: 106

Answers (1)

hsz
hsz

Reputation: 152216

Try with concat:

images.slice(2).concat(images.slice(0, 2))

Upvotes: 3

Related Questions