当前位置:网站首页>Recognize map
Recognize map
2022-06-26 00:57:00 【ivanfor666】
/* * Map * * * */
let myMap = new Map();
let keyObj = {};
myMap.set(keyObj, " Sum key keyObj The value of the Association ");
myMap.size;
// 1 myMap.get(keyObj);
// " Sum key keyObj The value of the Association " myMap.get({});
// undefined, because keyObj !== {}
// Traverse Map
for (var [key, value] of myMap) {
console.log(key + " = " + value);
}
for (var key of myMap.keys()) {
console.log(key);
}
for (let value of myMap.values()) {
console.log(value);
}
Array.from(myMap); // [[key,value]] Array.from(myMap.keys())
// Copy or merge Maps
let one = new Map([[1, 'one'], [2, 'two'], [3, 'three'],]);
new Map(one);
// Shallow clone
let first = new Map([[1, 'one'], [2, 'two'], [3, 'three'],]);
let second = new Map([[1, 'uno'], [2, 'dos']]);
// Merge two Map Object time , If there are duplicate key values , Then the latter will cover the former .
// The expansion operator is essentially to expand Map Object to array .
let merged = new Map([...first, ...second]);
console.log(merged.get(1));
// uno console.log(merged.get(2));
// dos console.log(merged.get(3)); // three
// Please note that ! by Map It's also possible to set object properties , But it can cause a lot of confusion .
let wrongMap = new Map()
wrongMap['bla'] = 'blaa'
wrongMap['bla2'] = 'blaaa2'
console.log(wrongMap) // Map { bla: 'blaa', bla2: 'blaaa2' }
// Map Medium key Is ordered . therefore , When iterating , One Map In the order in which the objects are inserted .
// utilize Map duplicate removal
var map = new Map;
[1, 1, 22, 33, 22, 33, 11, 1].forEach(item => map.set(item, true));
map.keys()
边栏推荐
猜你喜欢
About the use of hc-12 radio frequency module
1-10Vmware构建自定义的网络架构
Px4 system terminal for pixhawk
Making 3D romantic cool photo album [source code attached]
Optimized three-dimensional space positioning method and its fast implementation in C language
How to design the product roadmap?
Preordered clue binary tree
JS逆向案例:破解登录密码
Analyze the five root causes of product development failure
随便画画的
随机推荐
Example: use C # Net to teach you how to develop wechat official account (21) -- using wechat to pay online collection: H5 method
事物/现象/事情/东西/情况/表象
JS逆向案例:破解登录密码
mongodb
Preordered clue binary tree
STL tutorial 5-basic concepts of STL and the use of string and vector
Ssl/tls, symmetric and asymmetric encryption, and tlsv1.3
Optimized three-dimensional space positioning method and its fast implementation in C language
Openresty chapter 01 introduction and installation configuration
WordPress
Compiler Telegram Desktop end (tdesktop) en utilisant vs2022
FPGA notes -- implementation of FPGA floating point operation
JS reverse case: cracking login password
Modelsim simulation FFT core cannot be simulated solution (qsys)
Atlas200dk刷机
Binary sort tree
FreeRTOS+STM32L+ESP8266+MQTT协议传输温湿度数据到腾讯云物联网平台
[机缘参悟-30]:鬼谷子-内揵篇-同理心,站在对方的立场,拉近与对方的心理距离
No executorfactory found to execute the application
Why is it best to use equals for integer comparisons