ExtJS Array使用詳細介紹

來源:互聯網
上載者:User
/** * extjs Array使用詳細介紹 */(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 : 'uspcat',   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 用一個字串串連一個數組中所有元素 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); //返回結果 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", "swimming") // alert(arrlen);// 返回長度 4
 // 9數組元素翻轉(順序倒置) var myArray = ["one", "two", "three"]; myArray.reverse(); // alert(myArray);// 結果three,two,one
 // 10 移除第一個元素從一個數組,並返回那移除的那個元素
 var myFishs = ["angel", "clown", "mandarin", "surgeon"];
 // console.log("before: " + myFishs);
 var shifted = myFishs.shift(); // console.log("after: " + myFishs);
 // console.log("the removed element: " + shifted);
 // 11數組元素的排序(從小到大) /*  * 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 數組轉字串(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);
})();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.