es6基础(6)--数组扩展
//数组扩展
{
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)--数组扩展的更多相关文章
- ES6学习之数组扩展
扩展运算符(...将数组分割为用逗号分割的参数序列) console.log(...[1,2,3]) //1 2 3 可替换数组的apply写法: function test(x,y,z){ cons ...
- es6核心特性-数组扩展
1. Array.from() : 将伪数组对象或可遍历对象转换为真数组 如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,称为伪数组.典型的伪数组有函数的argu ...
- es6 语法 (数组扩展)
{ let arr = Array.of(3, 4, 7, 9, 11); console.log('arr', arr); //[3,4,7,9,11] let empty = Array.of() ...
- es6基础(3)-正则扩展
//正则扩展 { let regex=new RegExp('xyz','i'); let regex2=new RegExp(/xyz/i); console.log(regex.test('xyz ...
- 【ES6基础】字符串扩展
4.字符串扩展 (1)for...of循环遍历. let foo = [1,2,3,4,5,6] for(let i of foo){ console.log(i); } 结果: (2)include ...
- es6基础(4)--字符串扩展
//字符串扩展 { console.log('a','\u0061'); console.log('s','\u20BB7');//超过了0xffff console.log('s','\u{20BB ...
- es6基础(7)--函数扩展
{ //有默认值的后面如果有参数必须要有默认值 function test(x,y="world"){ console.log(x,y) } test('hello');//hel ...
- es6基础(5)--数值扩展
{ //Number.isFinite数字是有尽的 console.log(Number.isFinite(15));//true console.log(Number.isFinite(NaN)); ...
- ES6数组扩展
前面的话 数组是一种基础的JS对象,随着时间推进,JS中的其他部分一直在演进,而直到ES5标准才为数组对象引入一些新方法来简化使用.ES6标准继续改进数组,添加了很多新功能.本文将详细介绍ES6数组扩 ...
随机推荐
- py-day1-6 python 5个灰魔法 【len,index索引,for循环,切片】
# 索引,下标,获取字符串中的某一个字符. test = 'MuMingJun' v = test[3] print(v) i # 切片 test = 'MuMingJun' v = test[0:- ...
- Spring AOP + PageHelper分页
1.增加依赖配置 <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweav ...
- hadoop发行版本之间的区别
Hadoop是一个能够对大量数据进行分布式处理的软件框架. Hadoop 以一种可靠.高效.可伸缩的方式进行数据处理.Hadoop的发行版除了有Apache hadoop外cloudera,horto ...
- C++和extern C
http://blog.csdn.net/gongmin856/article/details/44228453 C语言中的可变参数:va_list ,va_start,va_arg,va_end h ...
- Windows Phone Splash Screen
Why to use splash screen? Typically, you should use a splash screen in your app only if your app is ...
- C#中winform使用相对路径读取文件的方法
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f73b6cd0d3027fa3cf1fd579080101 ...
- Xshell配置ssh使用密钥公钥(publice key)登录
ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步:1.生成密钥( ...
- UML类图快速入门篇
1.关联 1.1双向关联: C1-C2:指双方都知道对方的存在,都可以调用对方的公共属性和方法. 在GOF的设计模式书上是这样描述的:虽然在分析阶段这种关系是适用的,但我们觉得它对于描述设计模式内的类 ...
- Flask--异常处理
异常处理: abort(404)-捕获HTTP抛出的统一状态码 @app.errorhandler-捕获全局异常错误码,捕获异常错误 @app.route("/demo4") de ...
- IDEA运行tomcat8.5.35源代码
前提环境,安装和配置好java1.8+环境,maven,IDEA 1.下载Tomcat源代码:https://tomcat.apache.org/download-80.cgi#8.5.35 2.创建 ...