Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 757
vinuta Avatar asked Nov 18 '25 08:11

vinuta


1 Answers

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.

like image 108
Swoox Avatar answered Nov 21 '25 00:11

Swoox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!