O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing Items from the Array

var week = ["sun", "Mon", "Tue", "Wed", "thur", "Fri", "sat"]; var weekdays = week.splice(1,5); var day = week.pop(); // weekdays= ["Mon", "Tue", "Wed", "thur", "Fri"] // day = "sat" // week = ["sun", "Mon", "Tue", "Wed", "thur", "Fri"];

You can remove the last item in the array using pop(). If you want to remove items in the middle of the array, you need to use splice(index, count), where index is the index to begin removing items from and count is the number of items to remove.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required