Horje
how to find last element in array in javascript Code Example
js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
javascript get last element of array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
how to get last item in array javascript
let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];
js get last element of array
var arr = [1, 2, 3];
var last_element = arr.reverse()[0];
how to find last element in array in javascript
// how to find last element in array in javascript
// 1. Array.prototype.length
const arr = [1,2,3,4,5];
console.log(arr[arr.length - 1]);
// Result: 5

// 2. Array.prototype.slice()
const last = arr.slice(-1);
console.log(+last);
// Result: 5
last element of an array
int[] array = {1,2,3};
System.out.println(array[array.length - 1]);




Javascript

Related
if array ontains any item of another array js Code Example if array ontains any item of another array js Code Example
check if array exists in another array javascript Code Example check if array exists in another array javascript Code Example
search string javascript Code Example search string javascript Code Example
jquery clone object Code Example jquery clone object Code Example
date in javascript Code Example date in javascript Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8