extjs 中Array使用详细介绍
来源:互联网 发布:大数据与精准教学 编辑:程序博客网 时间:2024/06/17 02:33
/**
* 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);
})();
- extjs 中Array使用详细介绍
- ExtJs 中Viewport的介绍与使用
- ExtJs 中Viewport的介绍与使用
- ExtJs grid使用详细
- ExtJS中MessageBox介绍
- Extjs:ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)-extjs
- ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)
- ExtJs使用总结(非常详细)
- JQuery中extend详细介绍和使用
- JQuery中extend详细介绍和使用
- JQuery中extend详细介绍和使用
- JQuery中extend详细介绍和使用
- oracle中动态SQL使用详细介绍
- 有关Struts2——ActionWildcard通配符的学习
- -(void)layoutSubviews什么时候触发调用
- 线段树
- Java网络编程中的序列化问题
- CentOS6.2 使用utorrent server
- extjs 中Array使用详细介绍
- 《Spring攻略》 第2章 高级Spring IoC容器
- gcc常用控制选项
- Subversion之路--实现精细的目录访问权限控制
- 创业笔记(九)
- 程序员思想偶尔出轨
- 将表转换成建表语句的存储过程
- linux上装FTP服务器
- 【算法设计】基于大规模语料的新词发现算法