John Wick John Wick - 1 year ago 213
Javascript Question

Get the last element in json array

how can I get the last element in the json array in the seats object. I want to get the countryid of with the value of 845, however this json is dynamic so i want to get the last element in the seats object. My api is structured like this. Thank you in advance.

"expirationDate":"April 21, 2017",

Answer Source

You can do this by accessing the jsonData.seats array by index, index of the last item being equal to jsonData.seats.length-1


var countryId = jsonData.seats[jsonData.seats.length-1].countryid
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download