vinuta
vinuta

Reputation: 423

Move an item in array to first position from last position in typescript

I have an array like this

var column = ["generic complaint", "epidemic complaint", "epidemic1 complaint", "epidemic2 complaint", "bal vivah", "name"]

I want the Last array element to be placed in first position , the sorted array should like this

var column = ["name","generic complaint", "epidemic complaint", "epidemic1 complaint", "epidemic2 complaint", "bal vivah"] 

need the solution in typescript

Upvotes: 2

Views: 2573

Answers (1)

Swoox
Swoox

Reputation: 3740

It's quite easy:

let last = column.pop();
column.unshift(last);

Pop is used to remove the last variable but you can assign it. Unshift will add a new item at the start of an array.

Upvotes: 6

Related Questions