Answers for "get last 5 value from an array javascript"

34

Javascript get last item in array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Posted by: Guest on July-25-2019
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
0

get last item in array javascript

Last Item In Array
Posted by: Guest on August-26-2021

Code answers related to "get last 5 value from an array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language