How to get last element of array in Javascript?

Today now in post i would share with you How to get last element of array in Javascript? Whenever some time we need to get last element of array value then we can use the bellow example. Here I will give you three way to get the last element value in jquery.

So let’s see the 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];

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →