Skip to content
Advertisement

How to get the last record in an array in AngularJS

I have an array of objects ObjectsArr= [Object1 , Object2,Object3, Object4] I want to show in my view the last object, how to do that in angularjs?

Advertisement

Answer

ObjectsArr[ObjectsArr.length - 1] — this will give you the last element in the array.
To display it in view:
{{ObjectsArr[ObjectsArr.length - 1]}}

This will work even when the array has zero entries.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement