by @kodeazy
How to get first element of an array in javascript?
var arry = ['element_1', 'element_2', 'element_3', 'element_4', 'element_5','element_6']
- I have an array of elements as above.
- we use
length
method to get the length of the array. -
as the in dexing of the array starts from
0
we subtract number by1
to get the last element as below.console.log(arry[arry.length-1]);
Output
'element_6 '