首页 > 其他 > 详细

基本概念之六

时间:2016-10-17 07:20:59      阅读:277      评论:0      收藏:0      [点我收藏+]

方法 - 把数组元素连接成一个字符串
.join() - .join(value) sample .join("*")

 

var landmarks = [];
landmarks.push("My House");
landmarks.push("Front path");
landmarks.push("Flikering streetlamp");
landmarks.push("Leaky fire hydrant");
landmarks.push("Fire station");
landmarks.push("Cat Rescue Center");
landmarks.push("My Old School");
landmarks.push("My friend‘s house");

产生随机数的方法 Math.random();得到0-1之间的一个随机小数
要产生0-10之间的随机小数,只要Math.random()*10
要取得一个长度为15的数组的随机索引,只要Math.floor(Math.random()*15)
Match.floor()只是截取整数部分,不是四舍五入

var randomWords = ["Explosion","Cave","Princess","Pen"];
randomWords[Math.floor(Math.random()*4)];

决策者程序之一

var phrases = [
"That sounds good.",
"Yes, you should definitely do that.",
"I‘m not sure that‘s a great idea.",
"Maybe not today?",
"Computer says no."
];
phrases[Math.floor(Math.random()*5)];

基本概念之六

原文:http://www.cnblogs.com/balian/p/5968383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!