Westside2004
asked on
Get Last Element in Array?
Hi,
I have this ajax call that returns an array. I need to somehow get the last value in the array. How can I do this? Here is the response from the ajax call. The last element in the array contains the value "state_id_5". I am trying to get this value out. This value may change also so I can't hardcode it. It may be state_id_7 or state_id_2. It will always be the last element in the array but I just not sure how to extract that out....
Thanks,
-ws
I have this ajax call that returns an array. I need to somehow get the last value in the array. How can I do this? Here is the response from the ajax call. The last element in the array contains the value "state_id_5". I am trying to get this value out. This value may change also so I can't hardcode it. It may be state_id_7 or state_id_2. It will always be the last element in the array but I just not sure how to extract that out....
Thanks,
-ws
r[154] = new Array();
r[154][0] = 2116;
r[154][1] = "William Jessup University";
r[155] = new Array();
r[155][0] = 2137;
r[155][1] = "Woodbury University";
r[156] = new Array();
r[156][0] = 2141;
r[156][1] = "World Mission University";
r[157] = new Array();
r[157][0] = "state_id_5";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oups :-)
var lastElementValue = r[r.length][0];