SlideShare a Scribd company logo
Prototype  Array
Introduction Prototype extends all native Javascript arrays with quite a few powerful methods.This is done in two ways: It mixes in the Enumerable module, which brings a ton of methods in already. It adds quite a few extra methods, which are documented in this section.  With Prototype, arrays become much, much more than the trivial objects we were used to manipulate, limiting ourselves to using their length property and their [] indexing operator. They become very powerful objects, that greatly simplify the code for 99% of the common use cases involving them.
Important Issues Many JavaScript authors have been misled into using the for…in JavaScript construct to loop over array elements. This kind of code just won’t work with Prototype. You see, the ECMA 262 standard, which defines ECMAScript 3rd edition, supposedly implemented by all major browsers including  MSIE , defines numerous methods on Array (§15.4.4), including such nice methods as concat, join, pop and push, to name but a few among the ten methods specified.
This same standard explicitely defines that the for…in construct (§12.6.4) exists to  enumerate the properties  of the object appearing on the right side of the in keyword. Only properties specifically marked as non-enumerable are ignored by such a loop. By default, the prototype and the length properties are so marked, which prevents you from enumerating over array methods when using for…in. This comfort led developers to use for…in as a shortcut for indexing loops, when it is not its actual purpose. However, Prototype has no way to mark the methods it adds to Array.prototype as non-enumerable. Therefore, using for…in on arrays when using Prototype will enumerate all extended methods as well, such as those coming from the Enumerable module, and those Prototype puts in the Array namespace (described in this section, and listed further below).
Example; You can revert to vanilla loops:     for  ( var   index  =  0 ;  index  < myArray.length; ++ index ) {      var  item = myArray[ index ];      // Your code working on item here...    }     Or you can use iterators, such as each :      myArray.each( function (item) {      // Your code working on item here...   });    This side-effect enforcement of the true purpose of for…in is actually not so much of a burden: as you’ll see, most of what you used to loop over arrays for can be concisely done using the new methods provided by Array or the mixed-in Enumerable module. So manual loops should be fairly rare.
By using iterators with lexical closures (anonymous functions that you pass to the iterators, that get invoked at every loop iteration), such as each, or relying on repetitive array construction (such as uniq), may yield unsatisfactory performance. In such cases, you’re better off writing manual indexing loops, but take care then to cache the length property and use the prefix ++ operator:     // Custom loop with cached length property: maximum full-loop performance on very large arrays!    for  ( var   index  =  0 , len = myArray.length;  index  < len; ++ index ) {      var  item = myArray[ index ];      // Your code working on item here...     }   
Moduleindex clear :: Array   clear() -> Array  -Clears the array (makes it empty). Example:   var  guys = [ 'Sam' ,  'Justin' ,  'Andrew' ,  'Dan' ];  guys.clear(); // -> [] guys // -> []   clone :: Array   clone() -> newArray  -Returns a duplicate of the array, leaving the original array intact. Example: var  fruits = [ 'Apples' ,  'Oranges' ];  var  myFavs = fruits.clone(); myFavs.pop();  // fruits -> ['Apples', 'Oranges'] // myFavs -> ['Apples']
compact :: Array   compact() -> newArray  -Returns a new version of the array, without any null/undefined values. Example: [ 'frank' , ,  'sue' , ,  'sally' ,  null ].compact()   // -> ['frank', 'sue', 'sally'] each :: Array   each(iterator) -> Array  -Iterates over the array in ascending numerical index order. This is actually the each method from the mixed-in Enumerable module.  It is documented here to clearly state the order of iteration. Example: [ 'one' ,  'two' ,  'three' ].each( function (s) {    alert(s); }); [  'hello' ,  'world' ].each( function (s,  index ) {    alert( index  +  ': '  + s); }); // alerts -> '0: hello' then '1: world'
first :: Array   first() -> value  -Returns the first item in the array, or undefined if the array is empty. Example: [ 'Ruby' ,  'Php' ,  'Python' ].first() // -> 'Ruby'   [].first() // -> undefined   flatten :: Array   flatten() -> newArray  -Returns a “flat” (one-dimensional) version of the array. Nested arrays are recursively injected “inline.” This can prove very useful when handling the results of a recursive collection algorithm, for instance. Example: [ 'frank' , [ 'bob' ,  'lisa' ], [ 'jill' , [ 'tom' ,  'sally' ]]].flatten()   // -> ['frank', 'bob', 'lisa', 'jill', 'tom', 'sally']  
from :: Array   Array.from(iterable) -> actualArray  -Clones an existing array or creates a new one from an array-like collection. This is an alias for the $A() method.  $A() method $A(iterable) -> actualArray  -Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but is the preferred way of casting to an Array.  Example: var  paras =  $A (document.getElementsByTagName( 'p' )); paras.each(Element.hide); $(paras.last()).show();
indexOf :: Array   indexOf(value) -> position  -Returns the position of the first occurrence of the argument within the array. If the argument doesn’t exist in the array, returns -1. Note: this uses the == equivalence operator, not the === strict equality operator. The bottom example below illustrates this. Minor note: this uses a plain old optimized indexing loop, so there’s no risk of extensions being detected by this method Example: [ 3 ,  5 ,  6 ,  1 ,  20 ].indexOf( 1 ) // -> 3  [ 3 ,  5 ,  6 ,  1 ,  20 ].indexOf( 90 ) // -> -1  [ 0 ,  false ,  15 ].indexOf( false ) // -> 0 instead of 1, because 0 == false!
inspect :: Array   inspect() -> String  -Returns the debug-oriented string representation of an array. Example:   [ 'Apples' , {good:  'yes' , bad:  'no' },  3 ,  34 ].inspect()  // -> &quot;['Apples', [object Object], 3, 34]“ NOTE: If you want to simply join the string elements of an array, use the native join method instead:  [ 'apples' ,  'bananas' ,  'kiwis' ].join( ', ' )  // -> 'apples, bananas, kiwis‘ see also inspect in object.inspect() Object.inspect(obj) -> String  -Returns the debug-oriented string representation of the object Example: Object.inspect() // -> 'undefined'  Object.inspect( null ) // -> 'null'  Object.inspect( false ) // -> 'false'  Object.inspect([ 1 ,  2 ,  3 ]) // -> '[1, 2, 3]'  Object.inspect( 'hello' ) // -> &quot;'hello'&quot;
last :: Array   last() -> value  -Returns the last item in the array, or undefined if the array is empty. Example: [ 'Ruby' ,  'Php' ,  'Python' ].last() // -> 'Python'   [].last() // -> undefined reduce :: Array   reduce() -> Array | singleValue  -Reduces arrays: one-element arrays are turned into their unique element, while multiple element arrays are returned untouched. Example: [ 3 ].reduce(); // -> 3   [ 3 ,  5 ].reduce(); // -> [3, 5]  
  reverse :: Array   reverse([inline = true]) -> Array  -Returns the reversed version of the array. By default, directly reverses the original. If inline is set to false, uses a clone of the original array. Example: var  nums = [ 3 ,  5 ,  6 ,  1 ,  20 ];  nums.reverse( false ) // -> [20, 1, 6, 5, 3] nums // -> [3, 5, 6, 1, 20]  nums.reverse() // -> [20, 1, 6, 5, 3] nums // -> [20, 1, 6, 5, 3] size   :: Array size() -> Number  -Returns the size of the array. This is just a local optimization of the mixed-in size method from the Enumerable module, which avoids array cloning and uses the array’s native length property. Example: $R ( 1 ,  10 ).size() // -> 10  [ 'hello' ,  42 ,  true ].size() // -> 3  $H ().size() // -> 0
toArray :: Array   toArray() -> newArray  -This is just a local optimization of the mixed-in toArray from Enumerable. This version aliases to clone, avoiding the default iterative behavior    See array.clone toJSON (1.5.1) :: Array   toJSON() -> String  -Returns a JSON string. Example: [ 'a' , {b:  null }].toJSON(); //-> '[&quot;a&quot;,{&quot;b&quot;:null}]'
Uniq :: Array   uniq() -> newArray   -Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned. Example: [ 'Sam' ,  'Justin' ,  'Andrew' ,  'Dan' ,  'Sam' ].uniq(); // -> ['Sam', 'Justin', 'Andrew', 'Dan']   [ 'Prototype' ,  'prototype' ].uniq(); // -> ['Prototype', 'prototype'] because String comparison is case-sensitive   Performance considerations   On large arrays with duplicates, this method has a potentially large performance cost:   Since it does not require the array to be sorted, it has quadratic complexity. Since it relies on JavaScript’s Array.concat, it will yield a new, intermediary array every time it encounters a new value (a value that wasn’t already in the result array).  More efficient implementations could be devised.  This page will get updated if such an optimization is committed.
Without :: Array   without(value...) -> newArray  -Produces a new version of the array that does not contain any of the specified values. Example: [ 3 ,  5 ,  6 ,  1 ,  20 ].without( 3 ) // -> [5, 6, 1, 20]   [ 3 ,  5 ,  6 ,  1 ,  20 ].without( 20 ,  6 ) // -> [3, 5, 1]

More Related Content

What's hot (20)

PDF
Advanced Python, Part 2
Zaar Hai
 
PDF
Advanced python
EU Edge
 
PDF
Template Haskell
Sergey Stretovich
 
PDF
Imugi: Compiler made with Python
Han Lee
 
PDF
Array String - Web Programming
Amirul Azhar
 
PPT
Python scripting kick off
Andrea Gangemi
 
PPT
Google collections api an introduction
gosain20
 
PDF
CoffeeScript
None
 
PDF
Docopt
René Ribaud
 
ODP
Introduction to Perl
Dave Cross
 
PDF
Improving Dev Assistant
Dave Cross
 
ODP
Introduction to Perl - Day 1
Dave Cross
 
PDF
Programming Language Swift Overview
Kaz Yoshikawa
 
PDF
Idiomatic Javascript (ES5 to ES2015+)
David Atchley
 
ODP
Advanced Perl Techniques
Dave Cross
 
PDF
Mastering Grammars with PetitParser
Lukas Renggli
 
ODP
Intermediate Perl
Dave Cross
 
PPT
Composing method
С. Ариука
 
PDF
Erubis徹底解説
kwatch
 
PPTX
Python Programming Essentials - M34 - List Comprehensions
P3 InfoTech Solutions Pvt. Ltd.
 
Advanced Python, Part 2
Zaar Hai
 
Advanced python
EU Edge
 
Template Haskell
Sergey Stretovich
 
Imugi: Compiler made with Python
Han Lee
 
Array String - Web Programming
Amirul Azhar
 
Python scripting kick off
Andrea Gangemi
 
Google collections api an introduction
gosain20
 
CoffeeScript
None
 
Docopt
René Ribaud
 
Introduction to Perl
Dave Cross
 
Improving Dev Assistant
Dave Cross
 
Introduction to Perl - Day 1
Dave Cross
 
Programming Language Swift Overview
Kaz Yoshikawa
 
Idiomatic Javascript (ES5 to ES2015+)
David Atchley
 
Advanced Perl Techniques
Dave Cross
 
Mastering Grammars with PetitParser
Lukas Renggli
 
Intermediate Perl
Dave Cross
 
Composing method
С. Ариука
 
Erubis徹底解説
kwatch
 
Python Programming Essentials - M34 - List Comprehensions
P3 InfoTech Solutions Pvt. Ltd.
 

Viewers also liked (8)

PPT
A Deeper look into Javascript Basics
Mindfire Solutions
 
PDF
Extending built in objects
Muhammad Ahmed
 
PDF
Js interpreter interpreted
Martha Schumann
 
PPT
JavaScript Event Loop
Thomas Hunter II
 
PDF
Node.js in action
Simon Su
 
PDF
Advanced Object-Oriented JavaScript
ecker
 
PPTX
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
PPTX
JavaScript Event Loop
Designveloper
 
A Deeper look into Javascript Basics
Mindfire Solutions
 
Extending built in objects
Muhammad Ahmed
 
Js interpreter interpreted
Martha Schumann
 
JavaScript Event Loop
Thomas Hunter II
 
Node.js in action
Simon Su
 
Advanced Object-Oriented JavaScript
ecker
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
JavaScript Event Loop
Designveloper
 
Ad

Similar to Array (20)

PDF
Ms Ajax Array Extensions
jason hu 金良胡
 
PDF
Underscore.js
timourian
 
PDF
15 ruby arrays
Walker Maidana
 
PPT
Object
mussawir20
 
PPT
Enumerable
mussawir20
 
PPT
Unit8
md751
 
PDF
GDI Seattle - Intro to JavaScript Class 2
Heather Rock
 
PPTX
Java script arrays
Frayosh Wadia
 
PPTX
Java script arrays
Frayosh Wadia
 
PPTX
PHP Array very Easy Demo
Salman Memon
 
PPTX
Net (f#) array
DrRajeshreeKhande
 
PPTX
Java script advance-auroskills (2)
BoneyGawande
 
DOC
Array properties
Shravan Sharma
 
PDF
Javascript
Vlad Ifrim
 
PDF
The Future of JavaScript (SXSW '07)
Aaron Gustafson
 
PPT
Prototype Utility Methods(1)
mussawir20
 
PPSX
javascript-Array.ppsx
VedantSaraf9
 
PPT
Javascript Primer
Adam Hepton
 
PPT
Js objects
Charles Russell
 
PDF
Useful javascript
Lei Kang
 
Ms Ajax Array Extensions
jason hu 金良胡
 
Underscore.js
timourian
 
15 ruby arrays
Walker Maidana
 
Object
mussawir20
 
Enumerable
mussawir20
 
Unit8
md751
 
GDI Seattle - Intro to JavaScript Class 2
Heather Rock
 
Java script arrays
Frayosh Wadia
 
Java script arrays
Frayosh Wadia
 
PHP Array very Easy Demo
Salman Memon
 
Net (f#) array
DrRajeshreeKhande
 
Java script advance-auroskills (2)
BoneyGawande
 
Array properties
Shravan Sharma
 
Javascript
Vlad Ifrim
 
The Future of JavaScript (SXSW '07)
Aaron Gustafson
 
Prototype Utility Methods(1)
mussawir20
 
javascript-Array.ppsx
VedantSaraf9
 
Javascript Primer
Adam Hepton
 
Js objects
Charles Russell
 
Useful javascript
Lei Kang
 
Ad

More from mussawir20 (20)

PPT
Php Operators N Controllers
mussawir20
 
PPT
Php Calling Operators
mussawir20
 
PPT
Database Design Process
mussawir20
 
PPT
Php Simple Xml
mussawir20
 
PPT
Php String And Regular Expressions
mussawir20
 
PPT
Php Sq Lite
mussawir20
 
PPT
Php Sessoins N Cookies
mussawir20
 
PPT
Php Rss
mussawir20
 
PPT
Php Reusing Code And Writing Functions
mussawir20
 
PPT
Php Oop
mussawir20
 
PPT
Php My Sql
mussawir20
 
PPT
Php File Operations
mussawir20
 
PPT
Php Error Handling
mussawir20
 
PPT
Php Crash Course
mussawir20
 
PPT
Php Basic Security
mussawir20
 
PPT
Php Using Arrays
mussawir20
 
PPT
Javascript Oop
mussawir20
 
PPT
Html
mussawir20
 
PPT
Javascript
mussawir20
 
PPT
Object Range
mussawir20
 
Php Operators N Controllers
mussawir20
 
Php Calling Operators
mussawir20
 
Database Design Process
mussawir20
 
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
mussawir20
 
Php Sq Lite
mussawir20
 
Php Sessoins N Cookies
mussawir20
 
Php Rss
mussawir20
 
Php Reusing Code And Writing Functions
mussawir20
 
Php Oop
mussawir20
 
Php My Sql
mussawir20
 
Php File Operations
mussawir20
 
Php Error Handling
mussawir20
 
Php Crash Course
mussawir20
 
Php Basic Security
mussawir20
 
Php Using Arrays
mussawir20
 
Javascript Oop
mussawir20
 
Javascript
mussawir20
 
Object Range
mussawir20
 

Recently uploaded (20)

PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
PDF
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Practical Applications of AI in Local Government
OnBoard
 
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 

Array

  • 2. Introduction Prototype extends all native Javascript arrays with quite a few powerful methods.This is done in two ways: It mixes in the Enumerable module, which brings a ton of methods in already. It adds quite a few extra methods, which are documented in this section.  With Prototype, arrays become much, much more than the trivial objects we were used to manipulate, limiting ourselves to using their length property and their [] indexing operator. They become very powerful objects, that greatly simplify the code for 99% of the common use cases involving them.
  • 3. Important Issues Many JavaScript authors have been misled into using the for…in JavaScript construct to loop over array elements. This kind of code just won’t work with Prototype. You see, the ECMA 262 standard, which defines ECMAScript 3rd edition, supposedly implemented by all major browsers including MSIE , defines numerous methods on Array (§15.4.4), including such nice methods as concat, join, pop and push, to name but a few among the ten methods specified.
  • 4. This same standard explicitely defines that the for…in construct (§12.6.4) exists to enumerate the properties of the object appearing on the right side of the in keyword. Only properties specifically marked as non-enumerable are ignored by such a loop. By default, the prototype and the length properties are so marked, which prevents you from enumerating over array methods when using for…in. This comfort led developers to use for…in as a shortcut for indexing loops, when it is not its actual purpose. However, Prototype has no way to mark the methods it adds to Array.prototype as non-enumerable. Therefore, using for…in on arrays when using Prototype will enumerate all extended methods as well, such as those coming from the Enumerable module, and those Prototype puts in the Array namespace (described in this section, and listed further below).
  • 5. Example; You can revert to vanilla loops:     for  ( var   index  =  0 ;  index  < myArray.length; ++ index ) {      var  item = myArray[ index ];      // Your code working on item here...    }     Or you can use iterators, such as each :      myArray.each( function (item) {      // Your code working on item here...   });    This side-effect enforcement of the true purpose of for…in is actually not so much of a burden: as you’ll see, most of what you used to loop over arrays for can be concisely done using the new methods provided by Array or the mixed-in Enumerable module. So manual loops should be fairly rare.
  • 6. By using iterators with lexical closures (anonymous functions that you pass to the iterators, that get invoked at every loop iteration), such as each, or relying on repetitive array construction (such as uniq), may yield unsatisfactory performance. In such cases, you’re better off writing manual indexing loops, but take care then to cache the length property and use the prefix ++ operator:     // Custom loop with cached length property: maximum full-loop performance on very large arrays!    for  ( var   index  =  0 , len = myArray.length;  index  < len; ++ index ) {      var  item = myArray[ index ];      // Your code working on item here...     }   
  • 7. Moduleindex clear :: Array   clear() -> Array  -Clears the array (makes it empty). Example:   var  guys = [ 'Sam' ,  'Justin' ,  'Andrew' ,  'Dan' ];  guys.clear(); // -> [] guys // -> []   clone :: Array   clone() -> newArray  -Returns a duplicate of the array, leaving the original array intact. Example: var  fruits = [ 'Apples' ,  'Oranges' ];  var  myFavs = fruits.clone(); myFavs.pop();  // fruits -> ['Apples', 'Oranges'] // myFavs -> ['Apples']
  • 8. compact :: Array   compact() -> newArray  -Returns a new version of the array, without any null/undefined values. Example: [ 'frank' , ,  'sue' , ,  'sally' ,  null ].compact()   // -> ['frank', 'sue', 'sally'] each :: Array   each(iterator) -> Array  -Iterates over the array in ascending numerical index order. This is actually the each method from the mixed-in Enumerable module. It is documented here to clearly state the order of iteration. Example: [ 'one' ,  'two' ,  'three' ].each( function (s) {    alert(s); }); [  'hello' ,  'world' ].each( function (s,  index ) {    alert( index  +  ': '  + s); }); // alerts -> '0: hello' then '1: world'
  • 9. first :: Array   first() -> value  -Returns the first item in the array, or undefined if the array is empty. Example: [ 'Ruby' ,  'Php' ,  'Python' ].first() // -> 'Ruby'   [].first() // -> undefined   flatten :: Array   flatten() -> newArray  -Returns a “flat” (one-dimensional) version of the array. Nested arrays are recursively injected “inline.” This can prove very useful when handling the results of a recursive collection algorithm, for instance. Example: [ 'frank' , [ 'bob' ,  'lisa' ], [ 'jill' , [ 'tom' ,  'sally' ]]].flatten()   // -> ['frank', 'bob', 'lisa', 'jill', 'tom', 'sally']  
  • 10. from :: Array   Array.from(iterable) -> actualArray  -Clones an existing array or creates a new one from an array-like collection. This is an alias for the $A() method. $A() method $A(iterable) -> actualArray  -Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but is the preferred way of casting to an Array.  Example: var  paras =  $A (document.getElementsByTagName( 'p' )); paras.each(Element.hide); $(paras.last()).show();
  • 11. indexOf :: Array   indexOf(value) -> position  -Returns the position of the first occurrence of the argument within the array. If the argument doesn’t exist in the array, returns -1. Note: this uses the == equivalence operator, not the === strict equality operator. The bottom example below illustrates this. Minor note: this uses a plain old optimized indexing loop, so there’s no risk of extensions being detected by this method Example: [ 3 ,  5 ,  6 ,  1 ,  20 ].indexOf( 1 ) // -> 3  [ 3 ,  5 ,  6 ,  1 ,  20 ].indexOf( 90 ) // -> -1  [ 0 ,  false ,  15 ].indexOf( false ) // -> 0 instead of 1, because 0 == false!
  • 12. inspect :: Array   inspect() -> String  -Returns the debug-oriented string representation of an array. Example:   [ 'Apples' , {good:  'yes' , bad:  'no' },  3 ,  34 ].inspect()  // -> &quot;['Apples', [object Object], 3, 34]“ NOTE: If you want to simply join the string elements of an array, use the native join method instead:  [ 'apples' ,  'bananas' ,  'kiwis' ].join( ', ' )  // -> 'apples, bananas, kiwis‘ see also inspect in object.inspect() Object.inspect(obj) -> String  -Returns the debug-oriented string representation of the object Example: Object.inspect() // -> 'undefined'  Object.inspect( null ) // -> 'null'  Object.inspect( false ) // -> 'false'  Object.inspect([ 1 ,  2 ,  3 ]) // -> '[1, 2, 3]'  Object.inspect( 'hello' ) // -> &quot;'hello'&quot;
  • 13. last :: Array   last() -> value  -Returns the last item in the array, or undefined if the array is empty. Example: [ 'Ruby' ,  'Php' ,  'Python' ].last() // -> 'Python'   [].last() // -> undefined reduce :: Array   reduce() -> Array | singleValue  -Reduces arrays: one-element arrays are turned into their unique element, while multiple element arrays are returned untouched. Example: [ 3 ].reduce(); // -> 3   [ 3 ,  5 ].reduce(); // -> [3, 5]  
  • 14.   reverse :: Array   reverse([inline = true]) -> Array  -Returns the reversed version of the array. By default, directly reverses the original. If inline is set to false, uses a clone of the original array. Example: var  nums = [ 3 ,  5 ,  6 ,  1 ,  20 ];  nums.reverse( false ) // -> [20, 1, 6, 5, 3] nums // -> [3, 5, 6, 1, 20]  nums.reverse() // -> [20, 1, 6, 5, 3] nums // -> [20, 1, 6, 5, 3] size  :: Array size() -> Number  -Returns the size of the array. This is just a local optimization of the mixed-in size method from the Enumerable module, which avoids array cloning and uses the array’s native length property. Example: $R ( 1 ,  10 ).size() // -> 10  [ 'hello' ,  42 ,  true ].size() // -> 3  $H ().size() // -> 0
  • 15. toArray :: Array   toArray() -> newArray  -This is just a local optimization of the mixed-in toArray from Enumerable. This version aliases to clone, avoiding the default iterative behavior   See array.clone toJSON (1.5.1) :: Array   toJSON() -> String  -Returns a JSON string. Example: [ 'a' , {b:  null }].toJSON(); //-> '[&quot;a&quot;,{&quot;b&quot;:null}]'
  • 16. Uniq :: Array   uniq() -> newArray   -Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned. Example: [ 'Sam' ,  'Justin' ,  'Andrew' ,  'Dan' ,  'Sam' ].uniq(); // -> ['Sam', 'Justin', 'Andrew', 'Dan']   [ 'Prototype' ,  'prototype' ].uniq(); // -> ['Prototype', 'prototype'] because String comparison is case-sensitive   Performance considerations   On large arrays with duplicates, this method has a potentially large performance cost:   Since it does not require the array to be sorted, it has quadratic complexity. Since it relies on JavaScript’s Array.concat, it will yield a new, intermediary array every time it encounters a new value (a value that wasn’t already in the result array).  More efficient implementations could be devised. This page will get updated if such an optimization is committed.
  • 17. Without :: Array   without(value...) -> newArray  -Produces a new version of the array that does not contain any of the specified values. Example: [ 3 ,  5 ,  6 ,  1 ,  20 ].without( 3 ) // -> [5, 6, 1, 20]   [ 3 ,  5 ,  6 ,  1 ,  20 ].without( 20 ,  6 ) // -> [3, 5, 1]