Get the last element in json array

NB: Copy of @iuliu.net's code

use DOT at

example.at(-1)

 var jsonObject = {
        "expirationDate":"April 21, 2017",
        "remainingDays":325,
        "seats":[{"activeStatus":"S","pid":"TE70","firstName":"TE70","countryid":840},
                {"activeStatus":"Y","pid":"TE80","firstName":"TE80","countryid":845}]
                 }

var lastElement = jsonObject.seats.at(-1).countryid

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

simply:

var countryId = jsonData.seats[jsonData.seats.length-1].countryid

Try this:

var jsonObject = {
"expirationDate":"April 21, 2017",
"remainingDays":325,
"seats":[{"activeStatus":"S","pid":"TE70","firstName":"TE70","countryid":840},
        {"activeStatus":"Y","pid":"TE80","firstName":"TE80","countryid":845}]
 }

var lastElement = jsonObject.seats[jsonObject.seats.length-1].countryid