JavaScript Tutorials - Herong's Tutorial Examples
∟Creating, Accessing, and Manipulating Arrays
∟Array Object Instance Methods
This section provides a list of commonly used array object instance methods including split(), join(), sort(), etc.
As an object, an array has several commonly used object instance methods:
- this_array.concat(second_array) - The concat() method returns a new array
by concatenating the specified second array to the end of this array.
- this_array.join(delimiter) - The join() method returns a string
by joining all elements in this array with the specified delimiter.
- this_array.pop() - The pop() method returns the last element of this array
and removes it from this array reducing the array length by 1.
- this_array.push(exp1, exp2, ...) - The push() method adds specified expressions
as array elements to the end of this array and returns the last element added.
- this_array.reverse() - The reverse() method reverses positions of all elements in this array.
- this_array.shift() - The shift() method returns the first element of this array,
and removes it from this array reducing the array length by 1.
- this_array.unshift(exp1, exp2, ...) - The unshift() method adds specified expressions
as array elements to the front of this array and returns the new length of the array.
- this_array.slice(start_index, upto_index) - The slice() method returns a section of this array
between the specified indexes.
- this_array.splice(index, len, [exp1, exp2, ...]) - The splice() method removes "len" number of elements
from this array starting at the specified index. If optional expressions are specified, they will be
added at the specified index.
- this_array.sort() - The sort() method sorts all elements in alphabetic ascending order
in this array.
- this_array.indexOf(exp) - The indexOf() method returns the index of the first element that
matches the specified expression in this array. If no matches found, -1 will be turned.
The indexOf() method is supported only in JavaScript 1.6 and higher.
- this_array.lastIndexOf(exp) - The lastIndexOf() method returns the index of the last element that
matches the specified expression in this array. If no matches found, -1 will be turned.
The lastIndexOf() method is supported only in JavaScript 1.6 and higher.
A tutorial example will be given in the next section showing examples of using array object methods.
Table of Contents
About This Book
Introduction to JavaScript
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Flow Control Statements
►Creating, Accessing, and Manipulating Arrays
What Is an Array
Creating an Array Object
Accessing Array Elements with Indexes
Truncating and Iterating Array Elements
►Array Object Instance Methods
Array Object Instance Method Examples
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Introduction to Objects
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications
AJAX (Asynchronous JavaScript And XML)
References
Full Version in PDF/EPUB