"85@@86@@53".split('@@'); //['85','86','53'];
"banana".split(); //["banana"]; //( thanks peter (-: )
"president,senate,house".split(',',2); //["president", "senate"]
Array.prototype.join(separator)
["slugs","snails","puppy dog's tails"].join(' and '); //"slugs and snails and puppy dog's tails"
['Giants', 4, 'Rangers', 1].join(' '); //"Giants 4 Rangers 1"
[1962,1989,2002,2010].join();
String.prototype.replaceAll = function(find, replaceWith) {
return this.split(find).join(replaceWith);
}
"the man and the plan".replaceAll('the','a'); //"a man and a plan"
String.prototype.occurences = function(find, matchCase) {
var text = this;
matchCase || (find = find.toLowerCase(), text = text.toLowerCase());
return text.split(find).length-1;
}
document.body.innerHTML.occurences("div"); //google home page has 114
document.body.innerHTML.occurences("/div"); //google home page has 57
"England engages its engineers".occurrences("eng",true); //2
repeat
String.prototype.repeat = function(times) {
return new Array(times+1).join(this);
}
"go ".repeat(3) + "Giants!"; //"go go go Giants!"
[undefined,undefined,undefined,undefined].join("go ") + "Giants
var getDomain = function(url) {
return url.split('/',3).join('/');
}
getDomain("http://www.aneventapart.com/2010/seattle/slides/");
//"http://www.aneventapart.com"
getDomain("https://addons.mozilla.org/en-US/firefox/bookmarks/");
//"https://addons.mozilla.org"
var beheadMembers = function(arr, removeStr) {
var regex = RegExp("[,]?" + removeStr);
return arr.join().split(regex).slice(1);
}
//make an array containing only the numeric portion of flight numbers
beheadMembers(["ba015","ba129","ba130"],"ba"); //["015","129","130"]
var beheadMembers = function(arr, removeStr) {
var regex = RegExp("[,]?" + removeStr);
var result = arr.join().split(regex);
return result[0] && result || result.slice(1); //IE workaround
}
["ba015","ba129","ba130"].map(function(e) {
return e.replace('ba','')
}); //["015","129","130"]
//test 1 - using join/split
var arr = [], x = 1000;
while (x--) {arr.push("ba" + x);}
var beheadMembers = function(arr, regex) {
return arr.join().split(regex).slice(1);
}
var regex = RegExp("[,]?" + 'ba');
var timer = +new Date, y = 1000;
while(y--) {beheadMembers(arr,regex);};
+new Date - timer;
//FF 3.6 733ms
//Ch 7 464ms
//Sa 5 701ms
//IE 8 1256ms
//test 2 - using native map function
var arr = [], x = 1000;
while (x--) {arr.push("ba" + x);}
var timer = +new Date, y = 1000;
while(y--) {
arr.map(function(e) {
return e.replace('ba','')
});
}
+new Date - timer;
//FF 3.6 2051ms
//Cr 7 732ms
//Sf 5 1520ms
//IE 8 (Not supported)
var results = ['sunil', '23:09', 'bob', '22:09', 'carlos', 'mary', '22:59'];
var badData = results.join(',').match(/[a-zA-Z]+,[a-zA-Z]+/g);
badData; //["carlos,mary"]
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有