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()的更多相关文章

  1. 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 ...

  2. es5||es6 - array

    导航目录 /** * javascript - array * * ES5: * join() * push() * pop() * shift() * unshift() * sort() * re ...

  3. es6 Array.from + new Set 去重复

    // es6 set数据结构 生成一个数据集 里面的元素是唯一的 const items = new Set([1, 2, 3, 4, 5, 5, 5, 5]); // items 是个对象 item ...

  4. [ES6] 09. Destructuring Assignment -- 2

    Read More: http://es6.ruanyifeng.com/#docs/destructuring Array “模式匹配”,只要等号两边的模式相同,左边的变量就会被赋予对应的值: Ex ...

  5. [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( ...

  6. IE 浏览器不支持 ES6 Array.from(new Set( )) SCRIPT438: 对象不支持“from”属性

    [转]解决老浏览器不支持ES6的方法 现象: Array.from(new Set( )) SCRIPT438: 对象不支持“from”属性或方法   解决方法: 安装babel 引入browser. ...

  7. [ES6] 08. Destructuring Assignment -- 1

    Here is the way you get value from an object: var obj = { color: "blue" } console.log(obj. ...

  8. 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])) ...

  9. 解决低版本chrome浏览器不支持es6 Array.find()

     if (!Array.prototype.find) {  Array.prototype.find = function(predicate) {    'use strict';    if ( ...

随机推荐

  1. C# 导出word文档及批量导出word文档(1)

         这里用到了两个dll,一个是aspose.word.dll,另外一个是ICSharpCode.SharpZipLib.dll,ICSharpCode.SharpZipLib.dll是用于批量 ...

  2. 武汉科技大学ACM:1007: 不高兴的津津

    Problem Description 津津上初中了.妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她 报名的各科复习班.另外每周妈妈还会送她去学习朗诵.舞蹈和钢琴.但是津津如果一 ...

  3. 【转】setStyleSheet用法

    [转自]http://blog.csdn.net/seanyxie/article/details/5925723 使用setStyleSheet来设置图形界面的外观: QT Style Sheets ...

  4. Destoon后台修改公司会员资料信息的必填项限制修改

    /template/default/member/edit.htm module\member\admin\template\member_edit.tpl.php module\member\adm ...

  5. 【结构型】Decorate模式

    装饰模式主要意图是为对象扩展额外的职责,但对于用户来说,在使用行为上并没有任何的变化.在此举一个例子来解释该模式的含义.假如你手上有一张照片,此时可以给它盖上一片玻璃片,同时再套上一个精美的相框.如此 ...

  6. Oracle 存储过程介绍

    存储过程 1 CREATE OR REPLACE PROCEDURE 存储过程名 2 IS 3 BEGIN 4 NULL; 5 END; 行1: CREATE OR REPLACE PROCEDURE ...

  7. Codeforces 704D Captain America

    题意:平面上有n个点,每个点必须涂成红色和蓝色中的一种,花费各为r和b(对所有的点花费都一样).m条限制,每条限制形如"y=b这条直线上两种颜色的点的数目之差的绝对值不能超过c"或 ...

  8. $ npm install opencv ? 你试试?! 在windows环境下,使用node.js调用opencv攻略

    博主之前写过一篇文章<html5与EmguCV前后端实现——人脸识别篇>,叙述的是opencv和C#的故事.最近在公司服务器上更新了一套nodejs环境,早就听闻npm上有opencv模块 ...

  9. data-theme 几种值的样式

    代码片段: <div data-role="page"> <div data-role="header"> <h1>The ...

  10. swipejs

    http://swipejs.com/ http://www.scoop.it/t/javascript-for-mobile http://www.open-open.com/news/view/c ...