Answers for "how to return the last valye from an array"

80

javascript get last element of array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
Posted by: Guest on February-19-2020
1

get the last element of array javascript

let array = [1, 2, 3, 4, 5]
array.at(-1) // last element on array (5)
Posted by: Guest on December-01-2021
0

Get the Last Items in an Array

let array = [0, 1, 2, 3, 4, 5, 6, 7] console.log(array.slice(-1));>>>[7]console.log(array.slice(-2));>>>[6, 7]console.log(array.slice(-3));>>>[5, 6, 7]
Posted by: Guest on August-26-2021

Code answers related to "how to return the last valye from an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language