Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get Last Element in Array?

Posted on 2008-10-12
3
Medium Priority
?
3,860 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…

704 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