<script src="prototype.js"></script>
<script>
/**//*var arr = [1,2,3,4,8,5,4,3];
// 依次输出1,2,3,4,5,4,3
arr.each(
function (item, index) {
if (item < 6) {
alert(item);
} else {
throw $continue;
}
}
);
// 依次输出1,2,3,4
arr.each(
function (item, index) {
if (item < 6) {
alert(item);
} else {
throw $break;
}
}
);*/
/**//*
var arr = [1,2,3,4,5];
// arr = [1,2,3,4,5]
arr.reverse(false);
alert(arr.inspect());
// arr = [5,4,3,2,1]
arr.reverse();
alert(arr.inspect());
var arr = [1,2,3,4,5];
arr.reverse();
// 返回2在arr中的序号:1
var index = arr.indexOf(2);
alert(index)
var arr = [1,2,3,4,5];
// 不包含2和4,返回[1,3,5]
var newArr = arr.without(2,4);
alert(newArr.inspect());
var arr = [1,2,3,4,5];
arr.clear();
alert(arr[2]);
var arr = [1,2,3,4,5];
var arr2 = [2,4,6,8,10];
//[ [1,2],[2,4],[3,6],[4,8],[5,10]]
var newArr = arr.zip(arr2);
// [[1,4],[4,16],[9,36],[16,64],[25,100]]
var newArr2 = arr.zip(
arr2,
function (item) {
var newItem = item.collect(
function (item, index) {
return item * item;
}
);
return newItem;
}
);
alert(newArr.inspect());
alert(newArr2.inspect());
var arr = [5,2,3,1,4];
// 将arr排序
var arr = arr.sortBy(
function (item, index) {
return item;
}
);
arr.each(
function (item, index) {
alert(item);
}
);
var arr = [
{root: 1, square: 1},
{root: 2, square: 4},
{root: 3, square: 9},
{root: 4, square: 16},
{root: 5, square: 25}
];
var newArr = arr.pluck("square");
alert(newArr[4]);
var arr = [1,2,3,4,5];
var ptArr = arr.partition(
function (item, index) {
return item%2 == 1;
}
);
var oddArr = ptArr[0];
var evenArr = ptArr[1];
oddArr.each(
function (item) {
alert(item);
}
);
evenArr.each(
function (item) {
alert(item);
}
);
var arr = [1,2,3,4,5];
// 最大值
var max = -arr.min(
function (item, index) {
return -item;
}
);
// 最小值
var min = arr.min();
alert(max);
alert(min);
var arr = [1,2,3,4,5];
// 最大值
var max = arr.max();
// 最小值
var min = -arr.max(
function (item, index) {
return -item;
}
);
alert(max);
alert(min);
// 求集合中每一个元素的平方
Number.prototype.square = function () {
return this * this;
}
var arr = [1,2,3,4,5];
var newArr = arr.invoke("square");
alert(newArr[4]);
// 计算arr中所有数的乘积
var factorial = arr.inject(
1,
function (accumulator, item, index) {
return accumulator * item;
}
);
alert(factorial)
// 判断集合中是否包含”2“
var inc = arr.include(2);
alert(inc);
var arr = ["12345", "abc2", "cde", "fgh", "132ba"];
var newArray = arr.grep(
/2/,
function (item, index) {
return item + " contains 2";
}
)
newArray.each(
function (item) {
alert(item);
}
);
var arr = [1,2,3,4,5];
// 返回集合中所有的奇数
var oddArr = arr.findAll(
function (item, index) {
return item%2 == 1;
}
);
alert(oddArr[2]);
// 返回第一个大于3的元素
var ele = arr.find(
function (item, index) {
return (item > 3);
}
);
alert(ele);
var newArr = arr.collect(
function (item, index) {
return item * (index + 1);
}
);
var hasNegative = arr.any(
function (item, index) {
return (item < 0);
}
);
// 测试集合中的所有元素是否大于0
var allPositive = arr.all(
function(item, index) {
return (item > 0);
}
)
alert(allPositive);
arr.each(
function (item, index) {
alert("arr[" + index + "] = " + item);
}
);*/
</script>
分享到:
相关推荐
array.prototype.at 符合ESnext规范的Array.prototype.at / polyfill / replacement可以使用到ES3。 该软件包实现了接口。 它在ES3支持的环境中工作,并符合建议的。 因为Array.prototype.at依赖于接收方( this...
按副本更改数组向Array.prototype提供其他... start, end) -> Array Array.prototype.popped() -> Array Array.prototype.pushed(values...) -> Array Array.prototype.reversed() -> Array Array.prototype.shifted
prototype-160-api.rar prototype-160-api.rar
array.prototype.flatmap 符合ESnext规范的Array.prototype.flatMap填充程序/ polyfill / replacement可以使用到ES3。 该软件包实现了接口。 它在ES3支持的环境中工作,并符合建议的。 因为Array.prototype.flatMap...
array.prototype.values 符合ES2015规范的Array.prototype.values匀场/填充/替换值可一直使用到ES3。 该软件包实现了接口。 它可以在ES3支持的环境中工作并符合。 因为Array.prototype.values取决于接收方(“ ...
Learning-Robotics-Using-Python-Design-simulate-program-and-prototype-an-interactive-autonomous-mobile-robot-from-scratch-with-the-help-of-Python-ROS-and-Open-CV-.pdf
Prototype-1.6.0-zh.chm 中文手册。好不容易找到的最新的prototype手册。
array.prototype.flat 符合ES2019规范的Array.prototype.flat填充/填充/替换,可向下使用到ES3。 该软件包实现了接口。 它在ES3支持的环境中工作,并符合建议的。 因为Array.prototype.flat依赖于接收方( this值)...
python库。 资源全名:eth_prototype-0.2.0-py2.py3-none-any.whl
ember-disable-prototype-extensions-源码.rar
js代码-面试题---Array.prototype.sort() 底层原理,事件捕获与冒泡理解
代码如下: function test(){ //将参数转为一个数组 var args = Array.prototype.slice.apply(arguments); alert(args); } arguments在JavaScript语法中是函数特有的一个对象属性(Arguments对象),用来...
AS-23-Shcherbakov-Prototype-Pollution-Leads-to-RCE
Internet-of-Things-with-Python-Interact-with-the-world-and-rapidly-prototype-IoT-applications-using-Python.pdf
发现大多人都用了Array.prototype.slice.call(argments,0),一直不明白这句是干什么的。而昨天温习了slice()方法,再参考Function.call(thisArg[, arg1[, arg2[, ...]]]),还是不得而知(我脑筋转得慢:|)。
prototype-1.6.0.3.js prototype1.4中文手册(chm) prototype1.5中文手册(chm) prototype1.6英文手册(chm)
prototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rarprototype-1.6.0.rar
prototype-1.7.js