目录
  1. 1. Object
  2. 2. String
  3. 3. Array
  4. 4. Number
  5. 5. Math
  6. 6. Date
  7. 7. JSON
JavaScript常用API

本文主要记录JavaScript常用的API,其中包括Object,String,Array,Number,Math,Date和JSON七个对象的API。


Object

  1. Object.prototype() // 返回原型对象
  2. Object.hasOwnProperty() // 判断某个属性是否为当前对象自身的属性
  3. Object.toString() // 返回当前对象对应的字符串形式
  4. Object.keys() // 遍历对象的可枚举属性
  5. Object.getOwnPropertyName() // 遍历对象不可枚举的属性

String

  1. String.length() // 返回字符串长度
  2. String.replace() // 查找匹配字符并替换
  3. String.splice() // 提取匹配字符串
  4. String.split() // 分割字符串为数组
  5. String.chatAt() // 返回在指定位置的字符
  6. String.concat() // 连接多个字符串
  7. String.trim() // 去除两边空格
  8. String.toLowerCase() // 字符串转为小写
  9. String.toUpperCase() // 字符串转为大写

Array

  1. Array.length() // 数组长度

  2. Array.sort() // 数组元素排序

  3. Array.reserve() // 数组元素反转

  4. Array.concat() // 连接多个数组

  5. Array.push() // 添加数组末尾元素

  6. Array.pop() // 删除数组末尾元素

  7. Array.shift() // 删除数组第一位元素

  8. Array.unshift() // 添加数组第一位元素

  9. Array.join() // 用数组元素组成字符串

  10. Array.reduce() // 遍历数组
    array.reduce(function(total, currentValue, currentIndex, arr), initialValue)

  11. Array.map() // 遍历数组
    array.map(function(currentValue,index,arr), thisValue)

  12. Array.forEach() // 遍历数组
    array.forEach(function(currentValue, index, arr), thisValue)

  13. Array.filter() // 过滤数组
    array.filter(function(currentValue,index,arr), thisValue)

  14. Array.indexOf() // 搜索数组
    array.indexOf(item,start)


Number

  1. Number.toString() // 将数值转为字符串
  2. Number.toFixed() // 将数值转为指定位数的小数
  3. Number.toPrecision() // 将数值转为指定位数的有效小数

Math

  1. Math.random() // 返回0到1之间的一个随机数,区间为[0,1)
  2. Math.pow() // 指数运算
  3. Math.sqrt() // 返回参数的平方根
  4. Math.abs() // 返回参数的绝对值
  5. Math.round() // 四舍五入
  6. Math.ceil() // 向上取整
  7. Math.floor() // 向下取整

Date

  1. Date.getDate() // 回一个月中的某一天(1 ~ 31)
  2. Date.getDay() // 返回一周中的某一天(0 ~ 6)
  3. Date.getHours() // 返回小时(0 ~ 23)
  4. Date.getMinutes() // 返回分钟(0 ~ 59)
  5. Date.getSeconds() // 返回秒数(0 ~ 59)
  6. Date.getMonth() // 返回月份(0 ~ 11)
  7. Date.getFullYear() // 返回四位数字年份
  8. Date.getTime() // 返回1970年1月1日至今的毫秒数

JSON

  1. JSON.stringify() // 用于将对象转化成JSON字符串
  2. JSON.parse() // 用于将JSON字符串转化成对象。

文章作者: Hyman Choi
文章链接: http://yoursite.com/2019/08/01/JavaScript常用API/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 凌晨四点的拖拉机