• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Arrays and Objects > 3.7. Dividing Arrays

Dividing Arrays

NN 4, IE 5.5(Win)

Problem

You want to divide one array into two or more array segments.

Solution

To divide an array into two pieces, use the splice( ) method on the original array (the method is available in NN 4 or later and IE 5.5 or later for Windows). The splice( ) method requires two parameters that signify the zero-based index of the first item, and the number of items from there to be removed from the original array. For example, consider the following starting array:

var myArray = [10, 20, 30, 40, 50, 60, 70];

To create two arrays that have three and four items, respectively, first decide which items are to remain in the original array. For this example, we’ll remove the first three items to their own array:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint