JavaScript Match
JavaScript Match
版权声明:未经授权,严禁转载!
随机数
// 随机数 Math.random() 随机生成一个大于等于0且小于1的小数。
// 0>= r < 1 [0,1) 0~0.99999·····
console.log(Math.random());
console.log(Math.random());
console.log(Math.random());
console.log(Math.random()); // 计算概率
console.log(Math.random()<0.5?"❀":"字"); //谁去拿买卖
var r=Math.random();
console.log(
r<0.33?"张":
r<0.66?"王":
"乔"
);

// 取[0,10)之间一个数。
console.log(Math.random()*10);
// 取[0,5)之间一个数。
console.log(Math.random()*5); // 取[0,10)之间一个整数。
console.log(
// Math.random()*max
Math.floor(Math.random()*10)
);// math.floor() 取整 // 取[0,5)之间一个整数。
console.log(parseInt(Math.random()*5)); // math.floor() 取整 // 取[1,10] 之间一个整数。
console.log(Math.floor(Math.random()*10)+1); // math.floor() 取整
// 取[1,5]之间一个整数。
console.log(parseInt(Math.random()*5)+1); // math.floor() 取整 // 取 [22,35] 之间的随机整数
console.log(
// Math.floor(Math.random()*(max-min+1))+min
Math.floor(Math.random()*14)+22
);

案例:
随机生成一个四个字符的验证码,可包含大小写字母和数字
大写字母的 Unicode 为65-90,小写字母的 Unicode 为 97-122.
var arr=[];
//将所有可用字符保存到数组中
for(var i=0;i<10;i++){//0-9
arr.push(i);
}
for(var i=65;i<=90;i++){//A-Z
arr.push(String.fromCharCode(i));
}
for(var i=97;i<=122;i++){//a-z
arr.push(String.fromCharCode(i));
} //生成验证码
var text="";
for(var i=0;i<4;i++){
text+=arr[parseInt(Math.random()*arr.length)];//0-arr.length-1
}
console.log(text);

JavaScript Match的更多相关文章
- JavaScript match()方法使用
1.JavaScript match() 方法说明http://www.w3school.com.cn/jsref/jsref_match.asp 写法: stringObject.match(sea ...
- JavaScript match()方法和正则表达式match()
先介绍参数为普通字符串的使用方式,此时match方法的返回值是存放首次匹配内容的数组.如果没有找到匹配结果,返回null.语法结构: 1 str.match(searchvalue)参数解析:(1). ...
- JS学习之路之JavaScript match() 方法
match() 方法,在字符串内找到相应的值并返回这些值,()内匹配字符串或者正则表达式. 该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置. d ...
- JavaScript match 和 exec 备忘笔记
这是一道广为引用的面试题:var someText="web2.0 .net2.0"; var pattern=/(\w+)(\d)\.(\d)/g; var outCome_ex ...
- JavaScript match() 方法
match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置. var st ...
- JavaScript复习笔记——字符串
String构造器可以使用new调用,也可以不使用,但是,这两种调用的结果也是完全不一样的.用new调用的时候,String作为构造器函数,创建字符串对象.不使用new的时候,String用作一个常规 ...
- JS stringObject.Match()
JavaScript match() 方法 JavaScript String 对象 定义和用法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 inde ...
- 常见的几个js疑难点,match,charAt,charCodeAt,map,search
JavaScript match() 方法 定义和用法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 indexOf() 和 lastI ...
- javascript之正则表达式基础知识小结
javascript之正则表达式基础知识小结,对于学习正则表达式的朋友是个不错的基础入门资料. 元字符 ^ $ . * + ? = ! : | \ / ( ) [ ] { } 在使用这些符号时需要 ...
随机推荐
- PAT甲1115 Counting Nodes in a BST【dfs】
1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...
- 计蒜客 31451 - Ka Chang - [DFS序+树状数组][2018ICPC沈阳网络预赛J题]
题目链接:https://nanti.jisuanke.com/t/31451 Given a rooted tree ( the root is node $1$ ) of $N$ nodes. I ...
- Bitwise and Bit Shift Operators 位运算 取反 补码
Bitwise and Bit Shift Operators (The Java™ Tutorials > Learning the Java Language > Language B ...
- PHP之curl扩展
curl抓取远程文件 curl_init(); curl_setopt(); curl_exec(); curl_close(); 参数: //是curl收到HTTP response中的set-co ...
- Time Profiler Instrument分析卡顿
https://www.jianshu.com/p/080108c969e8 启动Time Profile:Xcode ——> Product ——> Profile ——> Tim ...
- arcgis server multipoint 服务 applyedit功能
首先打开arcmap,在catalog中新建 File GDB 在File GDB 中新建 Feature Class 类型选择 Multipoint 选择坐标 此时图层列表中有了新建的要素,点击Ed ...
- Mybatis插入数据后返回主键id
有时候使用mybatis插入数据后,需要用到记录在数据库中的自增id,可以利用keyProperty来返回,赋值给实体类中的指定字段. 单条记录插入并返回 First, if your databas ...
- 学习计划 mysql desc表结构分析
在完成数据表建表后,我们需要知道我们的表结构是什么,有没有和构造表时差异的地方. -- 简单查看表结构 desc 表名 这里拿数据库的一张表中做示例 mysql> desc rental; +- ...
- LoadRunner-关联问题(栏目列表较多关联不了想要的id)
新建了课程后之后有很多栏目,每个栏目对应一个partid,但我只想要期中一个. http://*********/course/work/workInfo.action?hwid=1547&c ...
- 【JMeter】如何用JMeter进行压力测试
[JMeter]如何用JMeter进行压力测试(调试脚本已再猪猪微信的收藏中进行了收藏哦,名字叫exam-wow.jmx) 一.用badboy录制压测过程形成脚本另存为jmeter格式文档. 二.JM ...