Indeks terakhir JavaScript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Grepper
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
System.out.print(Primes1.get(Primes1.size() - 1) + " ");
last element of array
const indices = [];
const array = ['a', 'b', 'a', 'c', 'a', 'd'];
const element = 'a';
let idx = array.lastIndexOf(element);
while (idx !== -1) {
indices.push(idx);
idx = (idx > 0 ? array.lastIndexOf(element, idx - 1) : -1);
}
console.log(indices);
// [4, 2, 0]
let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];
console.log(lastElement);
//Output: 16