JS 数据类型
由于主要是自己看,所以只收录了和 java 不一样的 API。
字符串中的转义序列 codeoutput\ '单引号 \" 双引号 \\ 反斜杠符 \ n 换行符 \ r 回车符 \ t 制表符 \ b 退格符 \ f 换页符数组操作
添加数据到数组末尾
array.push(["1",1]);
移除数组末尾数据
array.pop()
添加数据到数组头部
myArray.unshift(["1",1]);
移除数组首条数据
myArray.shift(); 函数相关
需先定义函数,然后再去调用
打印
console.log("Hi World");
局部变量的优先级更高
queue(队列)
=== 与 ==
=== 在 == 的基础上还会对比数据类型 1 == "1" true 1 === "1" false
未定义 undefined
undefined,是一个关键字,而不是一个字符串。
删除 delete
delete myDog.tails;
检查对象属性
.hasOwnProperty(propname) 方法来检查对象是否有该属性。如果有返回 true,反之返回 false。
- // Setupvar myObj = {gift: "pony",pet: "kitten",bed: "sleigh"};function checkObj(checkProp) { if(myObj.hasOwnProperty(checkProp)){ return myObj[checkProp]; }return "Not Found";}checkObj("gift");
for 循环
js 里面好像直接用 var 代替了所有数据类型
- for (var i = 1; i <= 5; i++) {
- myArray.push(i);
- }
算法 21 点算法
牌数点数 + 12,3,4,5,607,8,9-110,'J','Q','K','A'
- //设置牌数var count = 0;function cc(card) {if(card<7&&card>1){ count +=1; //原谅我比较挫}else if(card==10||card=='J'||card=='Q'||card=='K'||card=='A'){ count-=1;} if(count<=0){ return count+" Hold"; }else{ return count+" Bet"; }}// Add/remove calls to test your function.// 提示: Only the last will displaycc(2); cc(3); cc(7); cc('K'); cc('A');
随机数 random
随机小数(默认 0-1)
Math.random();
随机整数(10 以下)
Math.floor(Math.random()*10);
一定范围内随机数
Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/02-24/17500487.html