Microsoft Ajax library cheat sheet (1): array-type Extension

Source: Internet
Author: User

The original cheat sheet (PDF version) is here to download: http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip

Original copyright statement:

Copyright (c) 2004-2006, Milan Negovanhttp://www.AspNetResources.comAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:* Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer inthe documentation and/or other materials provided with thedistribution.* The name of the author may not be used to endorse or promote productsderived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITEDTO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER ORCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OROTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IFADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

NOTE: If [s] is marked as a static method, it can be used without instantiating an object.

[S] array. Add (array, item)

Add an item to the end of array.

var a = ['a','b','c','d'];
Array.add(a, 'e');
// a = ['a','b','c','d','e']

 

[S] array. addrange (array, items)

Add items in items to the end of array in sequence.

var a = ['a', 'b', 'c', 'd', 'e'];
var b = ['f', 'g','h'];
Array.addRange(a, b);
// a = ['a','b','c','d','e','f','g','h']

 

[S] array. Clear (array)

Clear all items in the array.

 

[S] array. Clone (array)

Returns shallow copy of the array ).

Note: the shortest copy only contains the items in the original array, whether it is a reference type or a value type. However, the shallow copy does not copy the referenced object. The new array and an element in the original array reference the instance of the same object.

var a = ['a','b','c','d'];
var b = Array.clone(a);
// b = ['a','b','c','d']

 

[S] array. Contains (array, item)

Determines whether the specified item is included in the array.

var a = ['red','green','blue','yellow'];
var b = Array.contains(a, "red");
// b = true

 

[S] array. dequeue (array)

Delete the first item from the original array and return the item.

var myArray = [],result = "";
Array.add(myArray, 'a');
Array.add(myArray, 'b');
Array.add(myArray, 'c');
Array.add(myArray, 'd');
result = Array.dequeue(myArray);
// myArray = ['b','c', 'd'], result = 'a'

 

[S] array. foreach (array, method, context)

Access each item in the array in sequence, but skip the undefined item.

var a = ['a', 'b', 'c', 'd'];
a[5] = 'e';
var result = '';
function appendToString(arrayElement, index, array) {
    // "this" is the context parameter, i.e. '|'.
    result += arrayElement + this + index + ',';
}
Array.forEach(a, appendToString, '|');
// result = a|0,b|1,c|2,d|3,e|4,

 

[S] array. indexof (array, item, start)

Search for an item in array and return its index in the array. If this array does not contain this item,-1 is returned.

var a = ['red', 'blue', 'green', 'blue'];
var myFirstIndex = Array.indexOf(a, "blue");
var mySecondIndex = Array.indexOf (a, "blue", (myFirstIndex + 1));
// myFirstIndex = 1, mySecondIndex = 3

 

[S] array. insert (array, index, item)

Insert a new item at a location in array.

var a = ['a', 'b', 'd', 'e'];
Array.insert(a, 2, 'c');
// a = ['a','b','c','d','e']

 

[S] array. parse (value)

Parses the real array object from the string expression.

var a = Array.parse ("['red', 'blue', 'green']");
// a[0] = 'red', a[1] = 'blue', a[2] = 'green'

 

[S] array. enqueue (array, item)

Add an item to the end of array. For more information, see array. dequeue (array ).

 

[S] array. Remove (array, item)

Remove (first appearance) from this array.

var a = ['a', 'b', 'c', 'd', 'e'];
Array.remove(a, 'c');
// a = ['a','b','d','e']
Array.removeAt(a, 2);
// a = ['a','b','e']

 

[S] array. removeat (array, index)

Removes the entry at the specified index from the array.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.