arraysangularjs

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?


Solution

  • 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.