I want to extract last n elements from array without splice
I have array like below , I want to get last 2 or n elements from any array in new array [33, 44]
[22, 55, 77, 88, 99, 22, 33, 44]
I have tried to copy old array to new array and then do splice.But i believe there must be some other better way.
var arr = [22, 55, 77, 88, 99, 22, 33, 44] ;
var temp = [];
temp = arr;
temp.splice(-2);
Above code is also removing last 2 elements from original array arr
;
So how can i just extract last n elements from original array without disturning it into new variable