[ES6] Array -- Destructuring and Rest Parameters && for ..of && Arrat.find()
We can use the destructing and rest parameters at the same time when dealing with Array opration.
Example 1:
let [first, ...remainingUsers] = ["Sam", "Tyler", "Brook"];
addActiveUsers(first, remainingUsers); // "Sam", ["Tyler", "Brook"]
Example 2:
function buildTopicInfo(topic){
let title = `<h1>${topic.title}</h1>`;
let author = `<small>${topic.author}<small>`;
return [title, author];
}
let topic = getCurrentTopic();
let [topicTitle, topicAuthor] = buildTopicInfo(topic);
Example 4:
let topicId = currentTopic();
let activeUsers = ["Sam", "Tyler", "Brook"]; for( let user of activeUsers ){
notifyTopicReply(topicId, user);
}
- for...of can only apply on the intereable object, like array, but not object

Example 5:
This code will report an type error, because for ... of can not be used for object.
let topicInfo = {
title: "New Features in JS",
replies: 19,
lastReplyFrom: "Tyler"
};
for(let [k, v] of topicInfo){
console.log(`${k} - ${v}`);
}
Example 6: Array.find()
let recentTopics = [
{
title: "Semi-colons: Good or Bad?",
isLocked: true
},
{
title: "New JavaScript Framework Released",
isLocked: true
},
{
title: "ES2015 - The Shape of JavaScript to Come",
isLocked: false
}
]; recentTopics.find( (topic)=> !topic.isLocked)
[ES6] Array -- Destructuring and Rest Parameters && for ..of && Arrat.find()的更多相关文章
- vue.js 进行初始化遇到的关于core-js的错误@core-js/modules/es6.array.find-index]
D:\vuejselement\workSpace\zutnlp_platform_show>cnpm install --save core-js/modules/es6.array.find ...
- es5||es6 - array
导航目录 /** * javascript - array * * ES5: * join() * push() * pop() * shift() * unshift() * sort() * re ...
- es6 Array.from + new Set 去重复
// es6 set数据结构 生成一个数据集 里面的元素是唯一的 const items = new Set([1, 2, 3, 4, 5, 5, 5, 5]); // items 是个对象 item ...
- [ES6] 09. Destructuring Assignment -- 2
Read More: http://es6.ruanyifeng.com/#docs/destructuring Array “模式匹配”,只要等号两边的模式相同,左边的变量就会被赋予对应的值: Ex ...
- [ES6] Array.findIndex()
In es5, you can use indexOf to get the index of one item in an array. In es6, you can use findIndex( ...
- IE 浏览器不支持 ES6 Array.from(new Set( )) SCRIPT438: 对象不支持“from”属性
[转]解决老浏览器不支持ES6的方法 现象: Array.from(new Set( )) SCRIPT438: 对象不支持“from”属性或方法 解决方法: 安装babel 引入browser. ...
- [ES6] 08. Destructuring Assignment -- 1
Here is the way you get value from an object: var obj = { color: "blue" } console.log(obj. ...
- es6 - array for-chrome
// 去重复 Array.from(new Set([1, 1, 2, 3])); // [1, 2, 3] console.log(Array.from(new Set([1, 1, 2, 3])) ...
- 解决低版本chrome浏览器不支持es6 Array.find()
if (!Array.prototype.find) { Array.prototype.find = function(predicate) { 'use strict'; if ( ...
随机推荐
- String[]和ArrayList和LinkedList区别
String[]和ArrayList和LinkedList区别 参考文档如下: http://www.blogjava.net/flysky19/articles/92775.html http:// ...
- java关键字 (jdk6),各自的含义是什么?
Abstract 抽象的 一个Java语言中的关键字,用在类的声明中来指明一个类是不能被实例化的,但是可以被其它类继承.一个抽象类可以使用抽象方法,抽象方法不需要实现,但是需要在子类中被实现. bre ...
- 学OpenGL的一些好的网站
好的资源太多,自己懂的太少,而今迈步从头越!!fighting...... 一些OpenGL资源链接 这是前几天自己简单整理的几个链接,希望对大家有用 顺便问一下http://www.spacesim ...
- 如何实现一个通用的IHttpHandler 万能的IHttpHandler HttpWebRequest文件上传
昨天遇到一个比较奇怪的需求,大致是需要在服务器上部署一个http服务,但是服务的具体功能不知道,以后在客服端实现.这里介绍一下系统背景,有一个系统运(部署在美国)行了很多年了,给系统产生了很多文件,现 ...
- 关于C++条件运算符(三目运算符)右结合的说明
C++条件运算符 a ? c : d;是右结合的,但是这个右结合要怎么理解呢? 对于a ? b : c ? d : e; 这样的表达式如果按照右结合来解读的话,那不应该是先运算c,然后返回d或者e,返 ...
- javascript之闭包深入理解(二)
在上一节中,详细理解了作用域链和垃圾回收机制,似乎这两点跟闭包关系不大,但是仔细想一想就会发现,其实不然.这一节将通过上一部分的说明详细理解闭包.请看代码: function createCompar ...
- 3.4 C与汇编程序的相互调用
为了提高代码执行效率,内核源代码中有些地方直接使用了汇编语言编制.这就会涉及在两种语言编制的程序之间相互调用的问题. 函数调用包括从一块代码到另一块代码之间的双向数据传递和执行控制转移.数据传递通过函 ...
- centos 6.5 安装阿里云的一键安装包(nginx+php5.4+mysql5.1)
安装阿里云提供的Linux一键安装web环境全攻略,本想着会有最复杂 ,没想到阿里云工程师提供的包没有任何限制(开始以为只能在阿里去的主机上使用).开源的精神就是好(注:我是伸手党). 环境 vmw ...
- Python3 如何优雅地使用正则表达式(详解三)
模块级别的函数 使用正则表达式也并非一定要创建模式对象,然后调用它的匹配方法.因为,re 模块同时还提供了一些全局函数,例如 match(),search(),findall(),sub() 等等.这 ...
- 不能将值 NULL 插入列 'ID',表 'EupStoreDemoDB.dbo.OrderDiary';列不允许有 Null 值。INSERT 失败。
MVC,使用EF构建实体.将数据存入数据库,执行到_db.SaveChange()时,会报如下错误: