本文為翻譯,英文原版的Cheat Sheet(PDF版本)在此下載:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip
原作著作權聲明:
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.
註:標註有[S]的為靜態方法,無須執行個體化對象即可使用。
[S] Array.add (array, item)
添加一項至Array的結尾。
var a = ['a','b','c','d'];
Array.add(a, 'e');
// a = ['a','b','c','d','e']
[S] Array.addRange (array, items)
將items中的項依次添加到Array的結尾。
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)
清除該Array中的所有項。
[S] Array.clone (array)
返回該Array的淺拷貝(Shallow Copy)。
注意:淺拷貝只包含原Array中的項,無論是參考型別還是實值型別。但淺拷貝並不會複製被引用的對象,新的Array和原Array中的某個元素引用的是同一個對象的執行個體。
var a = ['a','b','c','d'];
var b = Array.clone(a);
// b = ['a','b','c','d']
[S] Array.contains (array, item)
判斷指定的項是否包含在該Array中。
var a = ['red','green','blue','yellow'];
var b = Array.contains(a, "red");
// b = true
[S] Array.dequeue (array)
從原Array中刪除第一項,並返回該項。
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)
依次訪問該Array中的每一項,但跳過值為undefined的項。
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)
在Array中搜尋某一項,並返回其在該Array中的索引。若該Array中不包含該項,則返回-1。
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)
在Array中的某一位置插入新項。
var a = ['a', 'b', 'd', 'e'];
Array.insert(a, 2, 'c');
// a = ['a','b','c','d','e']
[S] Array.parse (value)
從字串表達方式解析出真正的Array對象。
var a = Array.parse ("['red', 'blue', 'green']");
// a[0] = 'red', a[1] = 'blue', a[2] = 'green'
[S] Array.enqueue (array, item)
添加一項至Array的結尾。請同時參考Array.dequeue (array)。
[S] Array.remove(array, item)
從該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)
從該Array中移除指定索引位置上的項。