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#中数据源绑定DataSource以及相关控件(DataGridView)的使用总结

    我们在编程过程中,会涉及到表格数据的显示,存储等,就可能涉及到DataGridView,DataSource, DataTable等概念. 下面我就我自己模糊的一些知识点串讲以下: 1)首先我要讲的是 ...

  2. ibatis.net调用oracle存储过返回游标SYS_REFCURSOR结果集

    最近在用ibatis.net框架和oracle 11g开发一套程序.其中有一个需求就是通过存储过程,查询指定条件的数据集. 但是在开发的过程中遇到了问题,问题如下: 1.如何通过ibatis.net执 ...

  3. 武汉科技大学ACM :1004: 华科版C语言程序设计教程(第二版)课后习题3.7

    Problem Description 输入无符号短整数k[hex.]和p[oct.],将k的高字节作为结果的低字节,p的高字节作为结果的高字节组成一个新的整数. Input k[hex.]和p[oc ...

  4. C++中的函数指针

    寒假这些天在看<The C++ Programming Language, 3rd>. 今天看到Chapter7 Function,里头好一些东西是C语言里没有的,比如overload.p ...

  5. jquery mobile 按钮部件(包含图标的使用)

    参考网址:http://api.jquerymobile.com/1.3/button/ 注:按钮的三种写法 <a href="#" class="ui-btn u ...

  6. java学习笔记 (9) —— Struts2 国际化

    1.Test.java package com.i18n; import java.util.Locale; public class Test1 { public static void main( ...

  7. 调整cell的间距

    -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier ...

  8. Linux系统挂载点与分区的关系(转载)

    计算机中存放信息的主要的存储设备就是硬盘,但是硬盘不能直接使用,必须对硬盘进行分割,分割成的一块一块的硬盘区域就是磁盘分区.在传统的磁盘管理中,将一个硬盘分为两大类分区:主分区和扩展分区.主分区是能够 ...

  9. Web开发-各状态码的意思

    常见的HTTP 1.1状态码以及它们对应的状态信息和含义 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新) 101 Switching Protoc ...

  10. android百度定位

    package com.aihunqin.test; import android.app.Activity; import android.os.Bundle; import android.wid ...