How to get last element of array in Javascript?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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:

Example

<script type="text/javascript">
    var languages = ["PHP", ".Net", "Java", "Javascript"];
    var last_element = languages[languages.length-1];
    console.log(last_element);
    var last_element2 = languages.pop();
    console.log(last_element2);
    var last_element3 = languages.slice(-1)[0];
    console.log(last_element3);
</script>

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 code chef

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 code chef →