Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3870
  • Last Modified:

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

0
Westside2004
Asked:
Westside2004
  • 2
1 Solution
 
gdarcanCommented:
r[r.length-1][0]
0
 
bluV11tCommented:
Try this:

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now