As an example, we created an array and in array holds multiple values. as well as, array store a variable.
Last Element of an array:- Cow
So, define an array with the holds all array values in a variable. the variable name has animals in which array defines multiple values of animals example.
There is an option to get an element that must get first and last both are possible. Likewise, first starting 0 to n times and last starting variable name and length -1.
var animals = ['monkey', 'lion', 'don', 'frog', 'cow']; var lastobject = animals[animals.length - 1]; document.write('First Element-'+ firstobject);
Js array method to get the first and last element. Also, must know about when get the first element to apply this method . Similarly, second, get an element .
Here, we provide both methods first and last with the example of code. Firstly, showing an array to get an element.
The First object of an array :- Name
Last object of an array:- Subject
JS Get Element of Array
Firstly, get the third element from the array you can put this method on your script arrayname. Similarly, pick every element the same as Js array.
<script> var student = ['name', 'rollno', 'address', 'contactno', 'subject']; var thirdobject = student; document.write('Third Element-'+ thirdobject); </script>
Finally, we example all types of method that Js gets the last element of the array. Whenever want another example and any issues regarding it. So, you can ask our comment section.