I am trying to retrieve the value of the "id" property from the last element in an array of JSON objects. While I can easily find each element by id, I specifically need to extract the value of the last "id" in the array of JSON objects. In the example provided below, the desired value is '3'. Appreciate any help in this regard!
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
}
})