Array.newIsArray = function(element){
return Object.prototype.toString.call(element).slice(8,-1).toLocaleLowerCase() === 'array';
}
Array.prototype.newIndexOf = function(element){
var index = -1;
for(var i = 0; i < this.length; i++){
if(this[i] === element && this[i] !== undefined){
index = i;
break;
}
}
return index;
};
var a = [1,2,3,4,,,5];
console.log(a.newIndexOf(undefined));
Array.prototype.newLastIndexOf = function(element){
var index = -1;
for(var i = this.length - 1; i >= 0; i--){
if(this[i] === element && this[i] !== undefined){
index = i;
break;
}
}
return index;
};
var a = [1,2,3,4,5,2,,,3];
console.log(a.newLastIndexOf(undefined));
Array.prototype.newForEach = function(fn){
for(var i = 0; i < this.length; i++){
if(i in this){
fn(this[i], i, this);
}
}
};
var a = [1,2,3,undefined,undefined,4,5,2,3];
a.forEach(function(e, i, arr){
console.log(e, i, arr);
})
Array.prototype.newEvery = function(fn){
var status = true;
for(var i = 0; i < this.length; i++){
if(i in this){
if(!(status = !!fn(this[i], i, this))){
break;
}
}
}
return status;
};
var a = [1,2,3,4,5,2,undefined,,3];
console.log(a.newEvery(function(){
console.log(arguments);
return 1;
}));
Array.prototype.newSome = function(fn){
var status = false;
for(var i = 0; i < this.length; i++){
if(i in this){
if(status = !!fn(this[i], i, this)){
break;
}
}
}
return status;
};
var a = [1,2,3,4,5,2,undefined,,3];
console.log(a.newSome(function(){
console.log(arguments);
return 0;
}));
Array.prototype.newMap = function(fn){
var array = new Array(this.length);
for(var i = 0; i < this.length; i++){
if(i in this){
array[i] = fn(this[i], i, this);
}
}
return array;
};
var a = [1,2,3,4,5,2,undefined,,3];
console.log(a.newMap(function(element, index, array){
console.log(arguments);
return element;
}))
Array.prototype.newFilter = function(fn){
var array = [];
for(var i = 0; i < this.length; i++){
if((i in this) && fn(this[i], i, this)){
array.push(this[i]);
}
}
return array;
};
var a = [1,2,3,4,5,2,undefined,,3];
console.log(a.newFilter(function(element, index, array){
console.log(arguments);
return element;
}))
Array.prototype.newReduce = function(fn){
if(this.length === 0){
throw new TypeError('Reduce of empty array with no initial value');
}
var result;
for(var i = 0; i < this.length; i++){
if(i in this){
if(!result){
result = this[i];
}else{
result = fn(result, this[i], i, this);
}
}
}
return result;
};
var a = [,,1,2,3,4,,6,7];
console.log(a.newReduce(function(a,b){
console.log(arguments);
return a + b;
}))
Array.prototype.newReduceRight = function(fn){
if(this.length === 0){
throw new TypeError('Reduce of empty array with no initial value');
}
var result;
for(var i = this.length - 1; i >= 0; i--){
if(i in this){
if(!result){
result = this[i];
}else{
result = fn(result, this[i], i, this);
}
}
}
return result;
};
var a = [,,1,2,3,4,,6,7];
console.log(a.newReduceRight(function(a,b){
console.log(arguments);
return a + b;
}))
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有