Jinuss's blog Jinuss's blog
首页
  • 源码合集

    • Leaflet源码分析
    • Openlayers源码合集
    • vue3源码
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

东流

Web、WebGIS技术博客
首页
  • 源码合集

    • Leaflet源码分析
    • Openlayers源码合集
    • vue3源码
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • React

  • Vue

  • JavaScript文章

  • 学习笔记

  • openlayers

  • threejs

  • MapboxGL

  • 工具

  • 源码合集

  • ECMAScript历年新特性

    • ECMAScript2016(ES7)新特性
      • 概述
      • ECMAScript2016(ES7)
        • includes
        • 对比JS其他搜索方法
        • 注意事项
        • 浏览器兼容性
        • **
        • 浏览器兼容性
    • ECMAScript2017(ES8)新特性
    • ECMAScript2018(ES9)新特性
    • ECMAScript2019(ES10)新特性
    • ECMAScript2020(ES11)新特性
    • ECMAScript2021(ES12)新特性
    • ECMAScript2022(ES13)新特性
    • ECMAScript2023(ES14)新特性
    • ECMAScript2024(ES15)新特性
    • ECMAScript2025(ES16)新特性
  • 前端
  • ECMAScript历年新特性
东流
2025-07-30
目录

ECMAScript2016(ES7)新特性

# 概述

ECMAScript2016于2016年6月正式发布, 本文会介绍ECMAScript2016(ES7),即ECMAScript的第7个版本的新特性。

以下摘自官网:ecma-262 (opens new window)

ECMAScript 2016 was the first ECMAScript edition released under Ecma TC39's new yearly release cadence and open development process. A plain-text source document was built from the ECMAScript 2015 source document to serve as the base for further development entirely on GitHub. Over the year of this standard's development, hundreds of pull requests and issues were filed representing thousands of bug fixes, editorial fixes and other improvements. Additionally, numerous software tools were developed to aid in this effort including Ecmarkup, Ecmarkdown, and Grammarkdown. ES2016 also included support for a new exponentiation operator and adds a new method to Array.prototype called includes.

# ECMAScript2016(ES7)

ES7只有两个新特性

  • Array.prototype.includes:用于判断数组是否存在某元素
  • **:指数运算符

# includes

includes方法会遍历数组(从索引0开始逐个检查,直到找到目标值或搜索完整个数组,如果存在该元素,则返回true,否则返回false。

includes的时间复杂度平均情况为O(n),其中n为数组长度。

# 对比JS其他搜索方法

方法 时间复杂度 是否提前终止 适用场景
includes O(n) 是 检查值是否存在
indexOf O(n) 是 获取值的索引
find O(n) 是 复杂条件搜索
some O(n) 是 条件匹配(返回布尔值)
Set.has O(1) 是 检查值是否存在

因此对于高频搜索或者是大数据量搜索,建议先将数组转为Set,再使用Set.has方法。

# 注意事项

  • includes方法可以查找NaN,而indexOf和indexOf方法不能查找NaN。
  • includes方法是不区分+0和-0

# 浏览器兼容性

# **

**运算符用于指数运算,即返回底数的指数次幂。比如x**y和Math.pow(x,y)是等价的

# 浏览器兼容性

编辑 (opens new window)
上次更新: 2025/07/30, 07:22:20
《Leaflet源码》笔记
ECMAScript2017(ES8)新特性

← 《Leaflet源码》笔记 ECMAScript2017(ES8)新特性→

最近更新
01
Set和WeakSet
08-04
02
Map和WeakMap
08-04
03
ECMAScript2025(ES16)新特性
07-30
更多文章>
Theme by Vdoing | Copyright © 2024-2025 东流 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式