es6 语法 (set 和 map)
2018-06-24 00:35:59来源:未知 阅读 ()
{ let list = new Set(); list.add(5); list.add(7); console.log('size', list, list.size); //{5, 7} 2 } { let arr = [1, 2, 3, 4, 5]; let list = new Set(arr); console.log('size', list.size); //5 } { let list = new Set(); list.add(1); list.add(2); list.add(1); console.log('list', list); //{1,2} let arr = [1, 2, 3, 1, '2']; let list2 = new Set(arr); console.log('unique', list2); //{1,2,3,'2'} } { let arr = ['add', 'delete', 'clear', 'has']; let list = new Set(arr); console.log('has', list.has('add')); //true console.log('delete', list.delete('add'), list); //{"delete", "clear", "has"} list.clear(); //清空 console.log('list', list); //{} } { let arr = ['add', 'delete', 'clear', 'has']; let list = new Set(arr); console.log('list', list); //{"add":"add","delete":"delete","clear":"clear","has":"has"} for (let key of list.keys()) { console.log('keys', key); //add delete clear has } for (let value of list.values()) { console.log('value', value); //add delete clear has } for (let [key, value] of list.entries()) { console.log('entries', key, value); // add add;delete delete;clear clear;has has; } list.forEach(function(item) { console.log('item', item); }) //add delete clear has } { let weakList = new WeakSet(); let arg = {}; weakList.add(arg); // weakList.add(2); console.log('weakList', weakList); //{} } { let map = new Map(); console.log('mapfirst', map); //{} let arr = ['123']; map.set(arr, 456); console.log('maptwo', map);//{array(1)=>456} console.log('map', map, map.get(arr)); //456 } { let map = new Map([ ['a', 123], ['b', 456] ]); console.log('map args', map);//{"a"=>123,"b"=>456} console.log('size', map.size);//2 console.log('delete', map.delete('a'), map);//true , {"b"=>456} console.log('clear', map.clear(), map);//{} } { let weakmap = new WeakMap(); let o = {}; weakmap.set(o, 123); console.log(weakmap.get(o));//123 }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:js基础
- 详解Webstorm 新建.vue文件支持高亮vue语法和es6语法 2020-02-07
- javascript setinterval 的正确语法如何书写 2019-12-08
- jQuery语法总结和注意事项 2019-10-16
- es6学习笔记(二) 2019-08-14
- js实现简单进度条 2019-08-14
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash