July 8, 2018
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
{{ObjectsArr[ObjectsArr.length - 1]}}
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.
index.html
<html> <head> <script src="angular.min.js"></script> <meta charset="utf-8"> <title>How to get the last record in an array in AngularJS</title> </head> <body > <div ng-app="liveapp"> <div ng-controller="livectrl"> <ul> <li ng-repeat="prod in listdata" ng-if="$last">{{prod}}</li> </ul> </div> </div> </body> </html>
app.js
var liveapp = angular.module('liveapp', ['ui.bootstrap']); liveapp.controller('livectrl', function ($scope) { $scope.listdata = [1,2,3] });
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.
var myliveadd = $scope.datasource[$scope.datasource.length - 1]
Angular.js get index of last element in 2d array in ng-repeat Example
<span ng-repeat="data in livearr"> {{data[data.length-1]}} </span> ------------- function myCtrl($scope) { $scope.livearr = [[1,2,6],[1,2,7,9],[2],[1,5,3,2,6]]; }
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.
$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); }]);