Link to home
Start Free TrialLog in
Avatar of Westside2004
Westside2004Flag for United States of America

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
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";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gdarcan
gdarcan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:

var lastElementValue = r[r.length][0];
Oups :-)