Michalis
Michalis

Reputation: 6926

Javascript - Change index of array element

I have an array with

[1,2,3,4,5]

I want to move "2" right (1 position at the time) or move "2" left

Can we do that with RxJS Operators?

Upvotes: 1

Views: 7706

Answers (1)

samnu pel
samnu pel

Reputation: 914

you can do it with regular javascript

Array.prototype.move = function(from, to) {
    this.splice(to, 0, this.splice(from, 1)[0]);
};

Upvotes: 6

Related Questions