Dictionaries in Python vs Javascript Objects

1

I have a question as to whether the Dict in Python and the Object in Javascript are the same concept and since I consider that if they do the same.

Example in Python

nombres = {}
nombres['Yoel'] = 1
nombres['Manolito'] = 2
nombres['Pepe'] = 3

Example in Javascript

var nombres = new Object();
nombres['Yoel'] = 1
nombres['Manolito'] = 2
nombres['Pepe'] = 3
    
asked by Yoel Macia Delgado 20.09.2017 в 09:35
source

1 answer

1

The concept is similar but they are not the same. Javascript objects are like a dictionary or map but have certain limitations. In fact, in the latest versions of the Javascript standard there is a new Map class to solve these limitations. From the MDN page on the class Map :

  

Objects are similar to Maps in that they both   allow to establish keys to values, recover those values,   delete keys, and detect if there is something stored in a key   determined. Because of this, the Objects have been used historically as   Historically maps; however, there are important differences between   Objects and Maps that make it better to use a Map.

     
  • An Object has a prototype, so there are default keys on the map. However, this can be drawn using map =   Object.create (null).
  •   
  • The keys of an Object are Strings, while they can be values of any type for a Map.
  •   
  • The size of a Map can be easily obtained while the size of an Object must be maintained manually.
  •   

This Map class if it comes to the same concept as the Python Dict

    
answered by 20.09.2017 в 10:47