JavaScript: Array Object and Properties

By Xah Lee. Date: . Last updated: .

Array is the value of a property key "Array" of the global object.

console.log( window.hasOwnProperty ( "Array" ) ) // true

Array is a function object.

// type of Array
console.log ( typeof Array === "function" ); // true
console.log ( Object.prototype.toString.call(Array) === "[object Function]" ) // true

The parent of Array is Function.prototype. 〔➤see JavaScript: Prototype and Inheritance

// parent of Array
console.log ( Object.getPrototypeOf ( Array ) === Function.prototype ); // true

The purpose of Array is:

  1. To create array objects.
  2. Used as a namespace to hold general purpose methods for working with array objects.
  3. Holds the property key "prototype". The value of Array.prototype is the parent object of all array objects.

Array Constructor

JavaScript: Array Constructor

〔➤see JavaScript: Create Array

〔➤see JavaScript: Understand JS Array

Properties


Array.prototype

JavaScript: Array Methods

Array.isArray()

Array.isArray ( arg )

Returns true if arg is a array object. (not a array-like object.) Else, false.

〔➤see JavaScript: What's Array-Like Object?

ES2015 §Indexed Collections#sec-array.isarray

Array.from()

Converts a iterable object items to array.

var ss = new Set ([3,4,5]); // a set object
var ar = Array.from(ss);    // convert set to array object
console.log(ar) // [ 3, 4, 5 ]

Array.from ( items, mapfn ) example:

// a set object
var ss = new Set ([3,4,5]);

// convert to array, but add one to each
var ar = Array.from(ss, x => x +1);

console.log(ar); // [ 4, 5, 6 ]

ES2015 §Indexed Collections#sec-array.from

Array.of()

Array.of ( …items )

Return a new array with elements of …items.

console.log( Array.of(3)) // [3]
console.log( Array.of(3,4)) // [3, 4]
console.log( Array.of(3,4, 'x')) // [3, 4, 'x']

ES2015 §Indexed Collections#sec-array.of

Reference

ES2015 §Indexed Collections#sec-array-objects

Array Topic

  1. JavaScript: Array Basics
  2. JavaScript: Understand JS Array
  3. JavaScript: Create Array
  4. JavaScript: Sparse Array
  5. JavaScript: What's Array-Like Object?
  6. JavaScript: How to Convert Array-Like Object to Array?
  7. JavaScript: Array How-To
  8. JavaScript: Array Constructor
  9. JavaScript: Array Object and Properties
  10. JavaScript: Array Methods
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.