//数组扩展
{
let arr=Array.of(3,4,6,7,9,11);//可以是空
console.log('arr=',arr);//[3,4,6,7,9,11]
}
{
//Array.from把伪数组或者集合变为数组
let p=document.querySelectorAll('p');
let pArr=Array.from(p);
pArr.forEach(function(item){
console.log(item.textContent);
})
//类似map
console.log(Array.from([1,3,5],function(item){
return item+2;
}))//[3,5,7]
}
{
//fill把数组中所有的都变成一个值
console.log('fill-7',[1,'a',undefined].fill(7));
//替换从第一个1开始到第三个3(1,3],被7替换
console.log('fill,pos',['a','b','c'].fill(7,1,3));
}
{
//输出索引
for(let index of ['1','c','ks'].keys()){
console.log('keys',index);
}
//输出值
for(let value of ['1','c','ks'].values()){
console.log('values',value);
}
//输出索引和值
for(let [index,value] of ['1','c','ks'].entries()){
console.log('entries',index,value);
}
}
{
//copyWithin(从哪个位置开始替换,从哪个位置开始读取,从哪个位置截止)
console.log([1,2,3,4,5].copyWithin(0,3,4));//[4,2,3,4,5]
}
{
//find查找,只会找满足条件的第一个值
console.log([1,2,3,4,5,6].find(function(item){
return item>3;
}))
//find查找,只会找满足条件的第一个值的下标
console.log([1,2,3,4,5,6].findIndex(function(item){
return item>3;
}))
}
{
//查看数组是否存在(x),可以找到NaN
console.log([1,2,NaN].includes(1))//true
console.log([1,2,NaN].includes(NaN))//true
}

es6基础(6)--数组扩展的更多相关文章

  1. ES6学习之数组扩展

    扩展运算符(...将数组分割为用逗号分割的参数序列) console.log(...[1,2,3]) //1 2 3 可替换数组的apply写法: function test(x,y,z){ cons ...

  2. es6核心特性-数组扩展

    1. Array.from() : 将伪数组对象或可遍历对象转换为真数组 如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,称为伪数组.典型的伪数组有函数的argu ...

  3. es6 语法 (数组扩展)

    { let arr = Array.of(3, 4, 7, 9, 11); console.log('arr', arr); //[3,4,7,9,11] let empty = Array.of() ...

  4. es6基础(3)-正则扩展

    //正则扩展 { let regex=new RegExp('xyz','i'); let regex2=new RegExp(/xyz/i); console.log(regex.test('xyz ...

  5. 【ES6基础】字符串扩展

    4.字符串扩展 (1)for...of循环遍历. let foo = [1,2,3,4,5,6] for(let i of foo){ console.log(i); } 结果: (2)include ...

  6. es6基础(4)--字符串扩展

    //字符串扩展 { console.log('a','\u0061'); console.log('s','\u20BB7');//超过了0xffff console.log('s','\u{20BB ...

  7. es6基础(7)--函数扩展

    { //有默认值的后面如果有参数必须要有默认值 function test(x,y="world"){ console.log(x,y) } test('hello');//hel ...

  8. es6基础(5)--数值扩展

    { //Number.isFinite数字是有尽的 console.log(Number.isFinite(15));//true console.log(Number.isFinite(NaN)); ...

  9. ES6数组扩展

    前面的话 数组是一种基础的JS对象,随着时间推进,JS中的其他部分一直在演进,而直到ES5标准才为数组对象引入一些新方法来简化使用.ES6标准继续改进数组,添加了很多新功能.本文将详细介绍ES6数组扩 ...

随机推荐

  1. sql语句实战

    1,排名,自身连接,用count,去重用distinct 2,累加,和上面一样,自身连接,用sum 3,count函数不用group by只有一组

  2. 从Excel文件中读取内容

    从Excel文件中读取内容 global::System.Web.HttpPostedFileBase file = Request.Files["txtFile"]; strin ...

  3. 编译NDK的source code一定要用release mode!

    编译NDK的source code一定要用release mode! 编译NDK的source code一定要用release mode! 编译NDK的source code一定要用release m ...

  4. 黄聪:bootstrap中模态框modal在苹果手机上会失效

    bootstrap中模态框在苹果手机上会失效 可将代码修改为<a  data-toggle="modal" data-target="#wrap" hre ...

  5. [蓝桥杯]ALGO-81.算法训练_动态数组使用

    从键盘读入n个整数,使用动态数组存储所读入的整数,并计算它们的和与平均值分别输出.要求尽可能使用函数实现程序代码.平均值为小数的只保留其整数部分. 样例输入: 样例输出: 样例输入: 样例输出: 题目 ...

  6. TCP/IP学习20180627-数据链路层-ethernet

    ifconfig :查看主機支持的網絡協議eth0:以太網接口lo:loopback接口 以太网(Ether-net)的定是指数字设备公司( Digital Equipment Corp.).英特尔公 ...

  7. Java 内存溢出(java.lang.OutOfMemoryError)情况总结

    最近做一个项目,因为分了十几个模块,但是每次在Eclipse中启动Tomcat必须加载四五个模块,这样出现了 java.lang.OutOfMemoryError 原因是Eclipse中Tomcat设 ...

  8. problem:为什么会有options请求

    为了安全考虑,浏览器对资源访问有同源限制的问题,也就是web应用程序只能访问和它同一协议同一域名同一端口的web应用程序上的资源. 通过跨域资源共享机制可以让资源在浏览器中访问与该资源本身不同域的资源 ...

  9. uoj #58【WC2013】糖果公园

    http://uoj.ac/problem/58 树上带修莫队模板题 #include<bits/stdc++.h> ; typedef long long i64; ],*ptr=buf ...

  10. BIO & NIO & NIO常见框架

    BIO & NIO BIO - Blocking IO - 同步式阻塞式IO --- UDP/TCP NIO - New  IO - 同步式非阻塞式IO AIO  - Asynchronous ...