How to get last element of array in Javascript?

By Hardik Savani | April 16, 2016 | | 4638 Viewer | Category : Javascript jQuery

Whenever you require to get last element value then you can use bellow example. I give you three way to get last element value in jquery. So let's see following example:


<script type="text/javascript">

var languages = ["PHP", ".Net", "Java", "Javascript"];

var last_element = languages[languages.length-1];


var last_element2 = languages.pop();


var last_element3 = languages.slice(-1)[0];



Do you want to expert php developer or developer team for your projects ?
Contact US