i am leaning how to use underscore in AngularJS. i try to extract last 2 element from array and show in alert. code is working but the problem is last two element is showing together in alert but i want to show each element in alert one after one. here is my code. please tell me what i should use as a result each last 2 element in alter one after one.
<div ng-app="myApp" ng-controller="MainCtrl">
</div>
var myApp = angular.module('myApp', []);
myApp.factory('_', function() {
return window._; //Underscore should be loaded on the page
});
myApp.controller('MainCtrl', function ($scope, _) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS2',
'AngularJS1'
];
var x = _.last($scope.awesomeThings, 2);
//alert(x[0]);
_.each([x],function(i)
{
alert(i);
});
});
i also follow these links
how to break the _.each function in underscore.js