• 5. 常用的字符串、数组、Math方法


    1. 字符串
    str.charAt(index) ——  找不到,返回空字符串
    str.indexOf(找东西) ——  找到了返回一个下标,没找到返回-1
    str.lastIndexOf()  ——  从后面往前找    同上
    str.substring(beginIndex[, endIndex])  ——   截取字符串,不包含最后一位
    str.split(切规则)  —— 返回一个数组
    str.toUpperCase() —— 把字符串转化为大写
    str.toLowerCase() —— 把字符串转化为小写
     
    2. 数组
    arr.push(value)  —— 数组保存在数组的最后一位
    arr.pop() —— 删除一个数,删除数组的最后一位
    arr.unshift(value) —— 往数组的第一位添加数据
    arr.shift() —— 删除数组的第一位
    arr.split(起始位置, 删除的个位, 元素1, 元素2... 元素N)
    arr.reverse() —— 数组反转
    arr.concat(arr1, arr2...) —— 数组连接
    arr.join(连接的规则) —— 返回的是一个字符串
     
    arr.sort() —— 对数组元素( json )进行排序
    sort(function(n1, n2) {
        return n1 - n2;
    });
    sort(function(json1, json2) {
        return json1.xx - json2.xx;
    });
     
    注:pop    shift都有返回值
     
    3. Math
    Math.random() —— 返回介于0~1之间的随机数
    Math.floor() —— 向下取整 -1
    Math.ceil() —— 向上取整 +1
    Math.abs() —— 绝对值 不会取整
    Math.round() —— 四舍五入    floor(value + 0.5)
    Math.pow(基数, 幂) —— 幂
    Math.sqrt() —— 开平方
    Math.max/min —— 最大最小值
  • 相关阅读:
    生成水印图片
    Java 生成图片-字体杂色去除
    java比较两个日期大小
    JS--添加option
    使用JS刷新showModalDialog窗口
    日期格式转换(String->Date)
    根据当前日期及出生日期,计算当前年龄(function)
    PHP的错误和异常处理
    IntelliJ IDEA15,PhpStorm10,WebStorm11激活破解
    apache相关配置
  • 原文地址:https://www.cnblogs.com/zouxinping/p/4807540.html
Copyright © 2020-2023  润新知