Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve last element id of array in Angular 2

I am trying to get id of last element of my array.

This is how I am fetching last element of my array

let last = this.Array[this.Array.length-1];
console.log(last);

Here is the console of last element of array-

Object {id: 48, title: "I'm used to this"}
 title: "I'm used to this"
 id:  48
__proto__:  Object

Here is the list on which I have looked already-

How to retrieve the clicked ElementId in angularjs?
How to get the object's id?
how to get the id name in html for any object and many more but I could not.

I just wanted to access id : 48, can any one help me to do so.
Thanks In Advance.

like image 387
S.Yadav Avatar asked Jun 14 '17 07:06

S.Yadav


1 Answers

Just do that:

let last:any = this.Array[this.Array.length-1];
console.log(last.id);
like image 153
Duannx Avatar answered Sep 18 '22 15:09

Duannx