ES6新增的数据类型-map

let obj1 = {a:1},obj2 = {a:2},obj3 = {};
obj3.name ='张三';
obj3[obj1] ='天空';
obj3[obj2] ='大海';
console.log(obj3);
//在一个对象中健会被当做字符串处理
console.log(obj1.toString());
console.log(obj2.toString());
console.log(obj1.toString() === obj2.toString());
//1.创建一个Map
let obj1 = {a:1},obj2 = {a:2};
const map =new Map([
['name','张三'],
['age','18'],
['sex','男'],
[obj1,'今天天气很好'],
[obj2,'适合敲代码'],
[[1,2],'hhh'],
['name','张三'],
['age','18'],
]);
console.log(map);
console.log(map.size); //6
//set和get
map.set('friends',['赵四']).set(['dog'],'小花');
console.log(map);
console.log(map.get('name')); //张三
//delete
map.delete(obj1)
console.log( map);
//has
console.log(map.has(obj1));
//clear
//清除所有
map.clear()
console.log(map);
//keys() values() entries()
console.log(map.keys());
//MapIterator {"name", "age", "sex", {…}, {…}, …}
console.log(map.values());
//MapIterator {"张三", "18", "男", "今天天气很好", "适合敲代码", …}
console.log(map.entries());
//MapIterator {"name" => "张三", "age" => "18", "sex" => "男", {…} => "今天天气很好", {…} => "适合敲代码", …}
//遍历
map.forEach(function (value,index) {
console.log(index +':' +value);
})
//注意事项
map.set({},'呵呵');
map.set({},'哈哈');
console.log(map);
【ES6新增的数据类型-map】console.log({}==={}); //false

    推荐阅读