zoukankan      html  css  js  c++  java
  • 基本概念之六

    方法 - 把数组元素连接成一个字符串
    .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)];

  • 相关阅读:
    Django动态下载文件
    单反学习
    网页开发
    从一堆数中随机取出一些值的方法
    C/C++使用HTTP协议上传
    django 初级(一) 配置与周边
    c++11
    外观模式
    sqlite
    linux程序设计1
  • 原文地址:https://www.cnblogs.com/balian/p/5968383.html
Copyright © 2011-2022 走看看