博客
关于我
【必备知识点】JavaScript里面那些天天使用的API
阅读量:401 次
发布时间:2019-03-05

本文共 1379 字,大约阅读时间需要 4 分钟。

初学JavaScript的核心方法总结

数组操作

元素插入与删除

  • array.push(item...):向数组尾部添加元素。
  • array.unshift(item...):向数组头部添加元素。
  • array.concat(item...):将元素插入数组,可接受多个数组并在尾部拼接。

核心方法

  • array.pop():从数组尾部删除一个元素。
  • array.shift():从数组头部删除一个元素。
  • array.reverse():反转数组顺序。
  • array.slice(start, end):复制数组一部分。
  • array.join(separator):将数组元素转换为字符串。
  • array.sort(comparefn):对数组进行排序,可自定义比较函数。
  • array.splice(start, deleteCount, item...):实现高级数组操作,支持插入和删除。

数字处理

转换方法

  • number.toString():将数字转换为字符串。
  • Number.parseInt(item):将字符串或其他可转换为数字的值转换为整数。
  • Number.parseFloat(item):将字符串或其他可转换为浮点数的值转换为浮点数。

判断方法

  • Number.isNaN(item):判断是否为不定值(NaN)。
  • Number.isInteger(item):判断是否为整数。

对象操作

属性操作

  • object.hasOwnProperty(item):判断对象是否拥有指定属性。

获取方法

  • object.keys():返回对象所有属性名的数组。
  • object.values():返回对象所有属性值的数组。

JSON数据处理

序列化与反序列化

  • JSON.stringify():将对象转换为标准JSON字符串。
  • JSON.parse():将JSON字符串转换为对象。

字符串操作

常用方法

  • string.charAt(pos):获取指定位置的字符。
  • string.concat(...items):将字符串拼接成一个新的字符串。
  • string.indexOf(searchString, position):查找子字符串在字符串中的起始位置。
  • string.lastIndexOf(searchString, position):查找子字符串在字符串中的末尾起始位置。
  • string.search(regexp):使用正则表达式查找子字符串。
  • string.substring(start, end):截取字符串(支持负数参数)。
  • string.slice(start, end):高级截取方法,支持负数参数。
  • string.split(separator, limit):将字符串拆分成数组。
  • string.toLowerCase():将字符串转换为小写。
  • string.toUpperCase():将字符串转换为大写。

日期处理

常用方法

  • date.toLocaleString():按本地格式显示完整日期和时间。
  • date.toLocaleDateString():显示完整的日期部分。
  • date.toLocaleTimeString():显示完整的时间部分。

以上方法是前端开发中经常使用的核心工具,熟练掌握这些方法将极大提升您的开发效率。

转载地址:http://qmzwz.baihongyu.com/

你可能感兴趣的文章
org.apache.http.conn.HttpHostConnectException: Connection to refused
查看>>
org.apache.ibatis.binding.BindingException: Invalid bound statement错误一例
查看>>
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.boot:spring boot maven plugin丢失---SpringCloud Alibaba_若依微服务框架改造_--工作笔记012
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
Orleans框架------基于Actor模型生成分布式Id
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>