Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between es6's map object and native object?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "what's the difference between es6 map objects and native objects". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between es6 map objects and native objects"!

The difference: 1, the type of the key in the combination of the key value pair stored in the native object object is a string, and the type of the key value pair stored in the map object can be any type; 2, the native object object obtains the key value using "Object.keys" and returns an array, while the map object uses the "map variable .keys ()".

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What is the difference between the map object and the native object of es6

Difference

Both object and Map store key-value pairs. But:

The key type of object is a string

The key type of map can be any type.

In addition, pay attention

Object gets the key value using Object.keys (returns an array)

Map uses the map variable .keys () (return iterator) to get the key value.

Sample code:

Js es6 map differs from native objects let a = {o: 1}; / / string console.log (typeof Object.keys (a) [0]); let map = new Map (); map.set (a, 'content') / / the output can be object or any type of console.log (map.keys (). Next ()); now that you have a better understanding of "what's the difference between es6's map object and native object", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report