I need to get the value of the "id" property of the last element in array of JSON objects. I can find each element by id but I also need to get the value of last "id" in the array of JSON objects. In the example below it is '3'. Thanks in advance!
let types: any[] =
[
{'id': '0', 'value': ''},
{ 'id': '1', 'value': '' },
{ 'id': '2', 'value': '' },
{ 'id': '3', 'value': '' },
];
let index = 0;
let indexNext = 1;
types.forEach((item) => {
if (item.id == index) {
item.value = 'Book';
console.log(item.value); //Book
}
if (item.id == indexNext) {
item.value = 'Magazine';
console.log(item.value); //Magazine
}
})