Get last item of array - Angular/JSON
12,198
You can do it like this:
var lastAddress = $scope.addresses[$scope.addresses.length - 1]
Author by
moh_abk
Updated on June 14, 2022Comments
-
moh_abk almost 2 years
I'm retrieving data from my API using Angular and adding the returned data to
$scope.addresses
I can get the first item in thearray
returned and assign it to avar firstAddress = $scope.addresses[0]
how can I get the last item in thearray
returned?