Home > Blockchain >  Closest to Python Dictionary in ReactJS
Closest to Python Dictionary in ReactJS

Time:01-08

I was wondering what would be the closest thing to a Python dictionary in React. Supose we have the following dict:

dict = {a:1, b:2, c:3}
dict[a]
>>> 1
dict[b]
>>> 2

How could i have a structure like that in ReactJS (with key-value pairs)?

CodePudding user response:

The closest to a Python dict in Javascript (that React uses) is simply an object.

const dict = {a: 1, b: 2, c: 3}

dict.a
>>> 1

dict.b
>>> 2

// you can access it like an array too: 

dict['a']
>>> 1

dict['b']

>>> 2
  •  Tags:  
  • Related