?
Solved

Need to shorten an array in JavaScript

Posted on 2011-10-02
2
Medium Priority
?
343 Views
Last Modified: 2012-05-12
When I take off the first item in the array, all I really do is shift the values up one index. Is there an easier way?

Anyway, I have this coded and it works. I would like to shorten the array by 1, so that calling the length property will be correct. How can I do that?

Thanks!
0
Comment
Question by:newbieweb
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36901252
var p = myarray.shift();  // put the first item of the array in p and remove it from the array
// http://www.w3schools.com/jsref/jsref_shift.asp
// Remove the first element of an array (this will also change the length of the array)


0
 

Author Closing Comment

by:newbieweb
ID: 36901261
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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

862 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