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.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.