JavaScript Array Object

Describes the JavaScript aray object including parameters, properties, and methods.

Parameters

  • arrayLength
  • elementN - Array element list of values

Properties

  • index
  • input
  • length - The quantity of elements in the object.
  • prototype - For creating more properties.

Methods

  • chop() - Used to truncate the last character of a all strings that are part of an array. This method is not defined so it must be written and included in your code.
    var exclamations = new Array("Look out!", "Duck!" )
    exclamations.chop()
    

    Causes the values of exclamations to become:

    Look out
    Duck
    
  • concat()
  • grep(searchstring) - Takes an array and returns those array element strings that contain matching strings. This method is not defined so it must be written and included in your code.

    words = new Array("limit","lines","finish","complete","In","Out")
    inwords = words.grep("in")
    

    The array, inwords, will be:

    lines, finish
    
  • join(delimiter) - Puts all elements in the array into a string, separating each element with the specified delimiter.
    words = new Array("limit","lines","finish","complete","In","Out")
    var jwords = words.join(";")
    

    The value of the string jwords is:

    limit;lines;finish;complete;In;Out
    
  • pop() - Pops the last string off the array and returns it. This method is not defined so it must be written and included in your code.
    words = new Array("limit","lines","finish","complete","In","Out")
    var lastword = words.pop()
    

    The value of the string lastword is:

    Out
    
  • push(strings) - Strings are placed at the end of the array. This method is not defined so it must be written and included in your code.
    words = new Array("limit","lines","finish")
    words.push("complete","In","Out")
    

    The array, words, will be:

    limit, lines, finish, complete, In, Out
    
  • reverse() - Puts array elements in reverse order.
    words = new Array("limit","lines","finish","complete","In","Out")
    words.reverse()
    

    The array, words, will be:

    Out, In, complete, finish, lines, limit
    
  • shift() - Decreases array element size by one by shifting the first element off the array and returning it. This method is not defined so it must be written and included in your code.
    words = new Array("limit","lines","finish","complete","In","Out")
    word = words.shift()
    

    The array, words, will be:

    In, complete, finish, lines, limit
    

    The string word will be:

    Out
    
  • sort() - Sorts the array elements in dictionary order or using a compare function passed to the method.
    words = new Array("limit","lines","finish","complete","In","Out")
    word = words.sort()
    

    The value of words becomes:

    In,Out,complete,finish,limit,lines
    
  • splice() - It is used to take elements out of an array and replace them with those specified. In the below example the element starting at element 3 is removed, two of them are removed and replaced with the specified strings. The value returned are those values that are replaced. This method is not defined so it must be written and included in your code.
    words = new Array("limit","lines","finish","complete","In","Out")
    words1 = words.splice(3, 2, "done", "On")
    

    The value of words becomes:

    limit, lines, finish, done, On, Out
    

    The value of words1 is set to:

    complete, In
    
  • split(deliimiter) - Splits a string using the delimiter and returns an array.
    words = new String("limit;lines;finish;complete;In;Out")
    var swords = words.split(";")
    

    The values in the array swords is:

    limit, lines, finish, complete, In, Out
    
  • unshift() - Places elementa at the start of an array
    words = new Array("finish","complete","In","Out")
    word = words.shift("limit","lines")
    

    The array, words, will be:

    limit, lines,finish, complete, In, Out