Solved

Get Last Element in Array?

Posted on 2008-10-12
3
3,851 Views
Last Modified: 2008-10-12
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
Comment
Question by:Westside2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
gdarcan earned 500 total points
ID: 22698642
r[r.length-1][0]
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22698651
Try this:

var lastElementValue = r[r.length][0];
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22698667
Oups :-)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question