【es6】es6使用集锦

时间:2023-03-09 21:21:28
【es6】es6使用集锦

一、查找数组中是否包含某个元素  使用includes  ,返回值为布尔值

arr.includes(searchElement, fromIndex);

解析:searchElement   查询元素

   fromIndex       开始查找的索引位置 

demo:

[2, 9, 7, 8, 9].includes(9); //true

 二、合并对象  使用Object.assign()

语法: Object.assign(target, …sources) target: 目标对象,sources: 源对象