/** * Extjs array usage */ (Function (){
Ext. onready (function (){
// 1 VaR myarray = [1, 2, 3, 4,-3,-4]; Ext. array. Every (myarray, function (item ){ If (item> 0 ){ Return true; } Else { // Alert (item ); Return false; } }, This );
// 2 VaR newarray = ext. array. Filter (myarray, function (item ){ If (item> 0 ){ Return true; } Else { Return false; } }, This ); // Alert (newarray. Join ("\ n "));
// 3 Object. Prototype. Get = function (Key, defv ){ If (this [Key]) { Return this [Key]; } Else { If (defv ){ Return defv; } } } VaR person = { Name: 'uscat ', Age: 26 } // Alert (person ['age']); // Alert (person. Get ('name '))
});
// 4 concatenating two or three Arrays VaR alpha = ["A", "B", "C"]; VaR numeric = [1, 2, 3]; VaR num3 = [7, 8, 9]; VaR alnum = Alpha. Concat (numeric );
// Alert (alnum)
VaR alnu3 = Alpha. Concat (numeric, num3 ); // Alert (alnu3 );
// 5 concatenating values to an array
VaR Alphas = ['A', 'B', 'C'];
VaR alnumeric = Alphas. Concat (1, [2, 3]); // Alert (alnumeric );
// 6 use a string to connect all elements in an array VaR A = new array ("wind", "Rain", "fire "); VaR myvar1 = A. Join (); // Alert (myvar1 ); VaR myvar2 = A. Join (","); // Alert (myvar2 ); VaR myvar3 = A. Join ("+ "); // Alert (myvar3 );
// 7 the pop method removes the last element from an array and returns that // Value to the caller. VaR myfish = ["angel", "Clown", "Mandarin", "surgeon"];
VaR popped = myfish. Pop (); // Alert (popped); // return result surgeon
// 8 adds one or more elements to the end of an array and returns the new // Length of the array.
VaR sports = ["soccer", "Baseball"]; VaR arrlen = sports. Push ("football", "playing Ming ") // Alert (arrlen); // return length 4
// 9 reverse the array element (inverted order) VaR myarray = ["one", "two", "three"]; Myarray. Reverse (); // Alert (myarray); // result three, two, one
// 10 remove the first element from an array and return the removed Element
VaR myfishs = ["angel", "Clown", "Mandarin", "surgeon"];
// Console. Log ("before:" + myfishs );
VaR shifted = myfishs. Shift (); // Console. Log ("after:" + myfishs );
// Console. Log ("the removed element:" + shifted );
// Sorting of array elements (from small to large) /* * Function comparenumbers (a, B) {return A-B; */
VAR numbers = [4, 2, 5, 3, 6, 0]; Numbers. Sort (function (a, B ){ Return A-B; }); // Console. Log (numbers );
// 12 array to string (returns a string representing the array and its elements. // Overrides the object. Prototype. tostring method .) VaR monthnames = new array ("Jan", "FEB", "Mar", "APR "); Monthnames. tostring (); // Console. Log (monthnames );
// 13 adds one or more elements to the front of an array and returns the new // Length of the array. VaR myfishh = ["angel", "Clown"]; Console. Log ("before:" + myfishh ); VaR unshiftedd = myfishh. unshift ("drum", "lion "); Console. Log ("after:" + myfishh ); Console. Log ("New length of array:" + unshiftedd );
})();
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.