Angularjs get last item Array Object and json Example

Angularjs get last item Array Object and json Example

Simple get the last record in an array in AngularJS Example

Syntax

[php]
{{ObjectsArr[ObjectsArr.length – 1]}}
[/php]

Example

Selecting last element in AngularJS array

Simple get the all the data array in angularjs to get last id and record to get using angular directives.

READ :  AngularJs Round to 2 decimal places

index.html
[php]




How to get the last record in an array in AngularJS

  • {{prod}}



[/php]

app.js
[php]
var liveapp = angular.module(‘liveapp’, [‘ui.bootstrap’]);
liveapp.controller(‘livectrl’, function ($scope) {
$scope.listdata = [1,2,3]
});
[/php]

Get last item of array – Angular/JSON

Simple get the all the data array/Angular/JSON in angularjs to get last id and record to get using angular directives.

[php]
var myliveadd = $scope.datasource[$scope.datasource.length – 1]
[/php]

Angular.js get index of last element in 2d array in ng-repeat Example

[php]

{{data[data.length-1]}}

————-
function myCtrl($scope) {
$scope.livearr = [[1,2,6],[1,2,7,9],[2],[1,5,3,2,6]];
}
[/php]

Get specific simple JSON object filter by id from JSON array in Example of AngularJS

Simple get the all the data array/Angular/JSON in angularjs to get last id and record to get using angular directives.

READ :  Angularjs routeprovider pass parameters to controller

[php]
$filter(‘filter’)(sdata.success, {id: 1})[0];
app.controller(‘liveCtrl’, [‘$filter’, function($filter) {
var sdata = { “success”: [
{
“id”: 12,
“name”: “laravel”
},
{
“id”: 2,
“name”: “angular”
},
{
“id”: 3,
“name”: “Vuejs”
}
] };

myobj = $filter(‘filter’)(sdata.success, function (d) {return d.id === 2;})[0];
console.log(myobj);
}]);
[/php]

Example

Leave a Comment