O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Ms Ajax Array Extensions

1.147 visualizações

Publicada em

Publicada em: Tecnologia
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Ms Ajax Array Extensions

  1. 1. Microsoft AJAX Library: Array Type Extensions Array.forEach (array, method, context) Array.add (array, item) Performs a specified action on each element of an Array object. Skips elements in Adds an element to the end of an Array object. the array that have a value of undefined. var a = ['a','b','c','d']; var a = ['a', 'b', 'c', 'd']; Array.add(a, 'e'); a[5] = 'e'; // a = ['a','b','c','d','e'] var result = ''; Array.addRange (array, items) function appendToString(arrayElement, index, array) { Copies all the elements of a specified Array object to the end of the array. // quot;thisquot; is the context parameter, i.e. '|'. result += arrayElement + this + index + ','; var a = ['a', 'b', 'c', 'd', 'e']; } var b = ['f', 'g','h']; Array.forEach(a, appendToString, '|'); Array.addRange(a, b); // result = a|0,b|1,c|2,d|3,e|4, // a = ['a','b','c','d','e','f','g','h'] Array.indexOf (array, item, start) Array.clear (array) Searches for the specified element of an Array object and returns its index. If item Removes all elements from an Array instance. is not found in the array, returns -1. Array.clone (array) var a = ['red', 'blue', 'green', 'blue']; Creates a shallow copy of an Array object. var myFirstIndex = Array.indexOf(a, quot;bluequot;); var mySecondIndex = Array.indexOf (a, quot;bluequot;, (myFirstIndex + 1)); // myFirstIndex = 1, mySecondIndex = 3 Remarks Array.insert (array, index, item) A shallow copy contains only the elements of the array, whether they are reference Inserts a single item into a specified index of an Array object. types or value types. However, it does not contain the referenced objects. The var a = ['a', 'b', 'd', 'e']; references in the new Array object point to the same objects as in the original Array.insert(a, 2, 'c'); Array object. In contrast, a deep copy of an Array object copies the elements and // a = ['a','b','c','d','e'] everything directly or indirectly referenced by the elements. Array.parse (value) var a = ['a','b','c','d']; var b = Array.clone(a); Creates an array from a string representation. // b = ['a','b','c','d'] var a = Array.parse (quot;['red', 'blue', 'green']quot;); Array.contains (array, item) // a[0] = 'red', a[1] = 'blue', a[2] = 'green' Determines whether the specified object exists as an element in an Array object. Array.enqueue (array, item) var a = ['red','green','blue','yellow']; Adds the specified object to the end of an Array object. See also Array.dequeue (). var b = Array.contains(a, quot;redquot;); // b = true Array.remove(array, item) Array.dequeue (array) Removes the first occurrence of the specified item from an Array object. Removes the first element from the Array object and returns it. var a = ['a', 'b', 'c', 'd', 'e']; var myArray = [],result = quot;quot;; Array.remove(a, 'c'); Array.add(myArray, 'a'); // a = ['a','b','d','e'] Array.add(myArray, 'b'); Array.removeAt(a, 2); Array.add(myArray, 'c'); // a = ['a','b','e'] Array.add(myArray, 'd'); result = Array.dequeue(myArray); Array.removeAt(array, index) // myArray = ['b','c', 'd'], result = 'a' Removes an element from an Array object at a specified index location. A function is static and is invoked without creating an instance of the object Based on Microsoft AJAX Library 1.0 • Compiled by Milan Negovan • www.AspNetResources.com • Last update: 2007-01-24