[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 ( ...
随机推荐
- python面对对象编程------4:类基本的特殊方法__str__,__repr__,__hash__,__new__,__bool__,6大比较方法
一:string相关:__str__(),__repr__(),__format__() str方法更面向人类阅读,print()使用的就是str repr方法更面对python,目标是希望生成一个放 ...
- (转)JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- Android--------使用gson解析json文件
##使用gson解析json文件 **json的格式有两种:** **1. {}类型,及数据用{}包含:** **2. []类型,即数据用[]包含:** 下面用个例子,简单的介绍gson如何解析jso ...
- (转)CentOS下用yum搭建LNMP服务器
原文链接:http://www.xiaohuai.com/2733 CentOS下搭服务器也折腾好几次了, 每次都知道个大概, 具体repo的地址什么的还都要现找, 实在不效率, 干脆整理记录下来. ...
- 关于oracle dblink的知识。
create database link WZGLconnect to MMCSG_GX(用户名)using '(description=(address_list=(address=(host=xx ...
- oralce中exists not exists in not in对于NULL的处理
1. 先讨论 in 与 not in中存在NULL的情况, sql语句如下: 1 select 1 result1 from dual where 1 not in (2, 3); 2 3 4 s ...
- oracle单行函数之类型转换
oracle数据类型转换:显示转换盒隐式转换 oracle自动完成转换
- CSS各种选择器
一.选择器 1.元素选择器 li{}最常用.最基本 2.派生选择器 li strong { } 标签间用空格分隔.定义了li标签中的strong标签的样式,css1中上下文选择器.css2中派生选择器 ...
- DZ 3.2 URL 伪静态配置 教程
原文转自:http://www.zccode.com/thread-682-1-1.html 教程说明: 1 首先需要下载URL重写工具,拷到服务器下面安装即可,这里配置IIS7(x64)伪静态. 工 ...
- postgres安装 以及修改postgres 密码
#postgres安装 apt-get install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 postgresql-s ...