Answers for "how do i get last element of array typescript only one from two elements"

2

how to get last element of array in typescript

var items: String[] = ["tom", "jeff", "sam"];

alert(items[items.length-1])
Posted by: Guest on November-10-2020
0

javascript get last 2 item in array

const cutOffFirstAndLastFive = (array) => {
  const [first, ...rest] = array;
  return rest.slice(-5);
}

cutOffFirstAndLastFive([1, 55, 77, 88]);

console.log(
  'Tests:',
  JSON.stringify(cutOffFirstAndLastFive([1, 55, 77, 88])),
  JSON.stringify(cutOffFirstAndLastFive([1, 55, 77, 88, 99, 22, 33, 44])),
  JSON.stringify(cutOffFirstAndLastFive([1]))
);
Posted by: Guest on August-26-2021

Code answers related to "how do i get last element of array typescript only one from two elements"

Code answers related to "Javascript"

Browse Popular Code Answers by Language