AngularJS Array-json Get Last Element using javascript

AngularJS Array-json Get Last Element using javascript

In this Post We Will Explain About is AngularJS Array-json Get Last Element using javascript With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to AngularJS Get Last Element using Array-jsonExample

In this post we will show you Best way to implement AngularJS – Extract date from last item in JSON object, hear for Getting the last element of an array with a split in AngularJSwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  PHP Application URL Routing Removing file extensions

How to get the last record in an array in AngularJS

HTML Part

  <div>
    <div>
<ul>
      <li>{{product}}</li>
</ul>
    </div>
    </div>

javascript

var liveapp = angular.module('liveapp', ['ui.bootstrap']);

liveapp.controller('liveCtrl', function ($scope) {

$scope.data = [1,2,3,4,5,6,7,8,9]
});

3 Methods To Get The Last Element Of An Array In Javascript

var liveArray = [1,2,3,4,5,6];

// Fastest method, requires the array is in a variable
liveArray[liveArray.length - 1];

// Also very fast but it will remove the HTML element from the array also, very easy this may or may not matter in your case.
liveArray.pop();

// Slowest way but very easy readable and doesn't require a variable
liveArray.slice(-1)[0]

Get the last element in an Array

index.html


<title>Simple Get the last element in an Array</title>


<!--
var x = new Array(0,1,2,3,4,5,6,7,8);
alert(x[x.length-1]);
//-->







Get last item of array – Angular/JSON

Fastest method with variables, requires the array is in a variable

READ :  Angular Multi Select Drop Down Options

var live_last_products = $scope.products[$scope.products.length - 1];
alert(live_last_products);

Example

I hope you have Got What is AngularJS – Extract date from last item in JSON object And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Add a Comment

Your email address will not be published. Required fields are marked *