• js 常用api记忆


    js API

    1.全局对象

    NAN 非数字值的特殊值
    infinity 代表正无穷的数据
    undefined

    2.函数属性

    eval() 可计算某个字符串,并返回字符串的值
    parseInt() 取整
    parseFloat() 取浮点数
    isNAN() 检查参数是否是非数字
    isFinite() 检查参数是否为无穷大

    3.处理URI的函数属性

    decodeURI() 可对encodeURI()函数编码过来的URI进行解析
    decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
    encodeURI 函数可把字符串作为 URI 进行编码
    encodeURIComponent 函数可把字符串作为 URI 组件进行编码。

    4.构造器属性

    Object 原型对象
    Function 函数
    Array 数组
    String
    Boolean
    Number
    Date
    RegExp 正则 包含三个方法(text(),exec(),compile())
    Error
    EvalError
    RangeError
    ReferenceError
    SyntaxError
    TypeError
    URIError

    5.全局对象其他属性

    Math 数学方法
    Jason

    6.Object对象

    构造器属性
    Object.prototype 表示对象Object的原型对象
    Object.getPrototype() 返回一个obj的原型
    Object.getOwnPropertyDescriptor(object, propertyname) 获得指定对象自身属性描述符
    Object.getOwnPropertyNames() 获得所有的属性名,以一个数组的形式返回
    Object.create(proto,[propertiesObject]) 创建一个拥有指定原型或若干原型指定原型的对象
    Object.defineProperty(object, propertyname, descriptor) 1:对象 2需要定义的属性或方法的名字 3:目标属性所拥有的特性
    Object.defineProperties(object, descriptors) 将一个属性或多个属性添加到对象,或修改现有属性
    Object.seal(obj)阻止修改现有属性的特性,并阻止添加新属性
    Object.freeze(obj)阻止修改现有属性的特性和值,并阻止添加新属性
    Object.preventExtensions(obj)阻止向对象添加新属性
    Object.isSealed(obj) 如果无法在对象中修改现有属性的特性,且无法向对象添加新属性,则返回true
    Object.isFrozen(obj) 如果无法在对象中修改现有属性的特性和值,且无法向对象添加新属性,则返回true
    Object.isExtensible() 返回一个值,该值指示是否可向对象添加属性
    Object.is(val1,val2) 返回一个值,该值指示两个值时候相同
    Object.keys(obj) 范湖对象可枚举属性和方法的名称
    原型对象属性
    proto指向该实例对象对应的原型对象 function foo(){}; var f1=new foo; console.log(f1.proyo===foo.prototype);//ture
    Object.prototype 指向实力对象的原型对象
    Object.prototype.constructor 返回对创建对象实例的Obj构造函数
    Object.prototype.toString() 方法返回一个表示该对象的字符串
    Object.prototype.toLocalString() 返回一个表示该对象的字符串.该方法主要是被本地化相关对象覆盖
    Object.protopyte.valueOf() 返回指定的原始值 好难理解
    Object.prototype.hasOwnProperty(prop) 用来判断某个对象是否含有指定属性
    Object.prototype.isPrototypeOf(obj) 用来测试一个对象是否存在另外一个对象的原型链上
    Object.prototype.propertyIsEnumberable(prop) 返回一个布尔值,表示属性是否是当前属性可枚举的布尔值

    7.Function对象

    构造器属性
    Function.prototype 储存function的原型对象
    Function.length 形参的个数
    原型对象属性
    Function.prototype.constructor
    Function.prototype.toString() 返回一个表当前函数的字符串
    Function.prototype.apply()
    Function.prototype.call()
    Function.prototype.bind() 方法会创建一个新的函数,第一个参数会作为运行时的this,之后的参数会在从传递的实参前传入作为他的参数

    8.Array对象

    构造器属性
    Array.prototype
    Array.isArray
    原型对象属性
    Array.prototype.constructor
    Array.prototype.toString()
    Array.prototype.toLocalString()
    Array.prototype.concat() 合并数组
    Array.prototype.join(spear) 将数组中的元素以一个字符串的形式导出,spear可为分隔符
    Array.prototype.pop() 删除数组的最后一个元素
    Array.prototype.push() 添加一个或一组元素,并返回新的数组
    Array.prototype.reverse() 颠倒数组中的元素 第一个会成为最后一个
    Array.prototype.shift() 删除数组中的第一个元素
    Array.prototype.slice(begin,end) 浅拷贝数组里的元素,包含左边不包含右边
    Array.prototype.sort(compareFunction) 默认元素做原地排序,compareFunction可以指定魔种排序方式
    Array.prototype.splice(start,deleteCount,item1) 用新元素替换就元素,以次修改数组的内容. start开始的index,delecount持续的个数,item1替换的内容,若为空,则表示删除 array.splice(2,0,'cat’) 把数组index=2替换为cat
    Array.prototype.unshift() 在开头添加一个或多个元素
    Array.prototype.indexOf() 返回元素的索引值,不存在为-1
    Array.prototype.lastIndexOf() 返回元素在数组中的最后一个索引值
    Array.prototype.every() 方法测试元素是否通过指定函数的测试
    function isBigEnough(element, index, array) { return (element >= 10);}
    var passed = [12, 5, 8, 130, 44].every(isBigEnough);// passed is false
    passed = [12, 54, 18, 130, 44].every(isBigEnough);// passed is true
    Array.prototype.some() 测试数组中是否有元素通过了指定函数的检测
    Array.prototype.forEach() 数组中每个元素提供一个指定的函数
    Array.prototype.map() 元素组中每一个元素调用一个方法后返回一个新的数组
    Array.prototype.filter()用指定的函数测试所有元素,并创建一个包含所有通过元素的数组
    Array.prototype.fill(value,start,end) 将数组摸一个区域的元素替换为value [1, 2, 3].fill(4, 1, 2) // [1, 4, 3]
    Array.prototype.reduce() 函数作为一个累加器,把数组中的每个元素(自左至右)累加成一个数组
    var flattened =[[0,1],[2,3],[4,5]].reduce(function(a,b){return a.concat(b),[]});
    //flattened[0,1,2,3,4,5]
    Array.prototype.reduceRight()

    9.String对象

    String.prototype
    String.fromCharCode() 可接受一个unicode值,然后返回一个字符串 document.write(72,69,76,76,79) //hello
    prototype属性
    String.prototype.constructor
    String.prototype.toString() 将一个逻辑值转化为字符串,并返回结果 var boo=new boolean(true) document.write(boo.toString())//true
    String.prototype.valueOf() 方法返回string的原始值
    String.prototype.charAt() 返回字符串中指定位置的字符
    String.prototype.charCodeAt() 返回字符串的unicode值
    String.prototype.concat() 将一个或多个字符串连接起来
    String.prototype.indexOf(searchValue,fromindex) 指定的值在字符串中首次出现的位置.从formindex开始
    String.prototype.lastIndexOf(searchValue,fromindex)指定值在字符串最后一次出现的位置.从from index开始
    String.prototype.localeCompare() 比较字符串的位置
    String.prototype.match(regexp) 当字符串匹配正则表达式(regexp)时,match会调用其方法
    String.prototype.replace() 用一个新的字符串替换原字符串中的部分字符串
    String.prototype.search(regex) 执行一个查找,看字符串对象与一个正则表达式是否契合
    String.prototype.slice(begin,end) 前拷贝字符串
    String.prototype.split() 把字符串分割成一个子字符串的数组 "Webkit Moz O ms Khtml".split( " " ) // ["Webkit", "Moz", "O", "ms", "Khtml”]
    String.prototype.substring(startindex,endindex) 返回字符串两个索引之间的子串
    String.prototype.toLowerCase() 将字符串转化为小写,并返回
    String.prototype.toLocalLowerCase() 字符串转化为小写。会根据本地化大小映射
    String.prototype.toUpperCase() 转化为大写
    String.prototype.toLocaleUpperCase()
    String.prototype.trim() 删除字符串两端的空白符

    10.Boolean对象

    构造器属性
    prototype
    原型对象的属性
    Boolean.prototype.constructor
    Boolean.prototype.toString() 布尔对象以字符串形式返回
    Boolean.prototype.valueOf() 返回原始值

    11.Number对象

    构造器属性
    prototype
    MAX_VALUE
    MIN_VALUE
    NaN
    NEGATIVE_INFINITY 负无穷
    POSITIVE_INFINITY 正无穷
    原型对象的属性
    Number.prototype.constructor
    Number.prototype.toString()
    Number.prototype.toLocaleString()
    Number.prototype.valueOf() 返回num的原始值
    eg:var numObj = new Number(10);
    console.log(typeof numObj); // object
    var num = numObj.valueOf();
    console.log(num); //
    Number.prototype.toFixed() 使用定点表示法来格式化一个数
    eg: var numObj = 12345.6789;
    numObj.toFixed(); // 返回 "12346":进行四舍五入,不包括小数部分
    numObj.toFixed(1); // 返回 "12345.7":进行四舍五入
    Number.prototype.toExponential() 以指数表示法返回该数值字符串表现形式
    eg: var numObj = 77.1234;
    numObj.toExponential(4)); //输出 7.7123e+1
    Number.prototype.toPrecision() 以指定精度返回该数据的字符串形式

    12.Math对象

    值属性
    E
    LN10
    LN2
    LOG2E
    LOG10E
    PI
    SQRT1_2
    SQRT2 2的平方根
    函数属性:
    abs() 绝对值
    acos()反cos
    asin()
    atan()
    atan2() 反正切函数
    ceil(x)返回一个大于或等于x的最小值
    cos()
    exp(x)函数返回 ex,x 表示参数
    floor(x)返回一个小于或等于x的最大值
    log()
    max()
    min()
    pow(base, exponent) 函数返回基数(base)的指数(exponent)次幂
    random()
    round()返回一个四舍五入最接近的值
    sin()
    sqrt()函数返回一个平方根
    tan()

    13.Date对象

    构造器属性
    Date.prototype
    Date.parse() 解析一个日期字符串,并返回为从1970到字符串的时间 Date.parse("Wed, 09 Aug 1995 00:00:00 GMT");
    Date.UTC() 返回从1970到指定日期的毫秒数 Date.UTC(96, 11, 1, 0, 0, 0)
    Date.now() 返回1970到当前时间的毫秒数
    原型对象属性
    Date.prototype.constructor
    Date.prototype.toString()
    Date.prototype.toDateString()
    Date.prototype.toTimeString() 差不多 格式不太相同
    Date.prototype.toLocaleString()
    Date.prototype.toLocaleDateString()
    Date.prototype.toLocaleTimeString()
    Date.prototype.valueOf() 返回对象的原始值
    Date.prototype.getTime() 返回一个时间的格林尼治时间
    eg: var birthday = new Date(1994, 12, 10);
    birthday.getTime()
    Date.prototype.getFullYear()
    Date.prototype.getUTCFullYear()
    Date.prototype.getMonth()
    Date.prototype.getUTCMonth()
    Date.prototype.getDate()
    Date.prototype.getUTCDate()
    Date.prototype.getDay()
    Date.prototype.getUTCDay()
    Date.prototype.getHours()
    Date.prototype.getUTCHours()
    Date.prototype.getMinutes()
    Date.prototype.getUTCMinutes()
    Date.prototype.getSeconds()
    Date.prototype.getUTCSeconds()
    Date.prototype.getMilliseconds() 根据本地时间,返回一个置顶日期对象的毫秒值
    Date.prototype.getUTCMilliseconds()
    Date.prototype.getTimezoneOffset()
    Date.prototype.setTime()
    Date.prototype.setFullYear()
    Date.prototype.setUTCFullYear()
    Date.prototype.setMonth()
    Date.prototype.setUTCMonth()
    Date.prototype.setDate()
    Date.prototype.setUTCDate()
    Date.prototype.setHours()
    Date.prototype.setUTCHours()
    Date.prototype.setMinutes()
    Date.prototype.setUTCMinutes()
    Date.prototype.setSeconds()
    Date.prototype.setUTCSeconds()
    Date.prototype.setMilliseconds()
    Date.prototype.setUTCMilliseconds()
    Date.prototype.toUTCString()
    Date.prototype.toISOString()方法返回一个iso格式的时间 YYYY-MM-DDTHH:mm:ss.sssZ时区总是etc,后缀加一个z
    Date.prototype.toJSON() 返回一个son格式的字符串

    14.RegExp对象

    构造器属性
    RegEx.prototype
    原型对象属性
    RegExp.prototype.exec() 为指定的一段字符串进行搜索匹配,返回一个数组活着null
    RegExp.prototype.test() 执行一个检索,用来查看正则表达式与指定字符串是否匹配
    RegExp.prototype.toString() 返回一个表示该正则表达式的字符串
    eg: foo = new RegExp("bar", "g”);
    alert(foo.toString()); // 显示 "/bar/g”
    实例属性:
    source 当前正则表达式模式文本的字符串
    global 是否匹配所有的选项,是一个只读属性,使用g标识
    ignoreCase 表示忽略大小写,只读属性,使用i标识
    multiline 表示多行字符串被看作多行,只读属性,使用m标识
    lastIndex

    后期会整理,时间待定

    来源:https://www.jianshu.com/p/b678628d114c
    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript
    https://www.cnblogs.com/caoru/p/13225082.html

  • 相关阅读:
    Chapter 4 持久存储数据对象
    pyhton Chapter3 读文件
    python笔记1
    C#读写txt文件
    机器学习第一讲
    Json对象
    表单加载
    多列树
    Java 基础【11】@注解
    Java 基础【06】复合赋值运算
  • 原文地址:https://www.cnblogs.com/lhongsen/p/13504625.html
Copyright © 2020-2023  润新知