For anyone migrating from python to node.js, it will be useful to know the equivalent data types in node.js for lists, tuples and dictionaries.
Do they exist? If not, are there node.js modules to achieve equivalent data structures in node.js?
Where Python has lists, JavaScript has arrays. These are declared using the exact same syntax as Python, with square brackets and commas:
var names = ["Foo", "Bar", "Baz"];
names[0]; # Foo
As an alternative to dictionaries you can use associative arrays, which are actually just JavaScript objects. Again, the syntax is similar to Python:
var dictionary = {"name": "Foo", "email": "[email protected]"};
dictionary["name"]; # Foo
JavaScript doesn't have tuples, but there is a tuple library on NPM, although I've never used it.
If you want to experiment with arrays and associative arrays, I'd recommend repl.it - the right-hand column is a REPL (read-eval-print loop), just like Python's equivalent when you open a terminal and type py
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With