JavaScript erhalten das letzte Element von Array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
Friendly Hawk
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];
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]
let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];
console.log(lastElement);
import _ from 'lodash';
let array = [ 1, 2, 3 ];
_.last(array); // 3