JS: Array.prototype

By Xah Lee. Date: . Last updated: .

Array.prototype is the value of the property key "prototype" of the function Array.

[see JS: Array Object]

console.log( Array.hasOwnProperty ( "prototype" ) ); // true

Type

Type of Array.prototype is object.

[see JS: Value Types]

console.log ( typeof Array.prototype === "object" ); // true

Array.prototype is a true array. Meaning, you can push elements to it, and with a magical length property.

console.log ( Array.isArray ( Array.prototype ) ); // true

console.log ( Array.prototype.length === 0); // true

Array.prototype.push ( "a", "b" );

console.log ( Array.prototype ); // [ 'a', 'b' ]

console.log ( Array.prototype.length === 2 ); // true

Parent

Parent of Array.prototype is Object.prototype.

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

[see JS: Prototype and Inheritance]

Purpose

Array.prototype is the parent of all array objects.

console.log (
Object.getPrototypeOf ( [3,4,5] ) === Array.prototype
); // true

Purpose of Array.prototype is to provide methods and properties useful for all array objects

[see JS: Understand JS Array]

Properties

Value Properties

  1. Array.prototype.length
  2. Array.prototype.constructor

Function Properties

modify elements

  1. Array.prototype.pop
  2. Array.prototype.push
  3. Array.prototype.shift
  4. Array.prototype.unshift
  5. Array.prototype.splice
  6. Array.prototype.fill
  7. Array.prototype.copyWithin

concat and subarray

  1. Array.prototype.concat
  2. Array.prototype.slice

get elements

  1. Array.prototype.entries
  2. Array.prototype.keys
  3. Array.prototype.values
  4. Array.prototype [ Symbol.iterator ] (same as Array.prototype.values)

map

  1. Array.prototype.map
  2. Array.prototype.forEach
  3. Array.prototype.filter

sort, reverse

  1. Array.prototype.sort
  2. Array.prototype.reverse

find element

  1. Array.prototype.includes (find by value, return boolean)
  2. Array.prototype.indexOf (find by value, return index)
  3. Array.prototype.lastIndexOf
  4. Array.prototype.find (find by function, return value)
  5. Array.prototype.findIndex (find by function, return index)

true false on all

  1. Array.prototype.some
  2. Array.prototype.every

reduce to single value

  1. Array.prototype.reduce
  2. Array.prototype.reduceRight

convert to string

  1. Array.prototype.join
  2. Array.prototype.toString
  3. Array.prototype.toLocaleString
  1. Array.prototype [ Symbol.unscopables ]

ES2019


Array.prototype.toLocalString

myArray.toLocalString ()

ECMAScript® 2016 Language Specification#sec-array.prototype.tolocalestring

JS Array

  1. Understand JS Array
  2. Create Array
  3. Sparse Array
  4. Array-Like Object
  5. Array How-To

JS Object Reference

  1. Global
  2. Object
  3. Array
  4. Function
  5. String
  6. RegExp
  7. Date
  8. Set
  9. Map
  10. JSON
  11. Math
  12. Reflect
  13. Number
  14. Boolean
  15. Symbol
Liket it? I spend 2 years writing this tutorial. Help me spread it. Tell your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Object Ref
  5. DOM Scripting
  6. SVG
  7. Blog