While you will find a lot of similarities across all programming languages, it seems each has its own little quirks when trying to implement the same ideas. In Ruby, we have hashes which hold key/value pairs where the keys are generally symbols and values can be any sort of object (string,number,array,even another hash). In JavaScript, the same data type exists but is known as an Object Literal. These contain key/value pairs in much the same manner and can be manipulated as hashes can be in Ruby. There are some key differences though as explained below.
I won't cover how there are differences in how to create the hash in Ruby vs an object literal in JS, they are different languages so you would expect difference in syntax. I will dive into how to access items within the types of data.
Ruby allows you to access items in a hash through bracket notation. You can see this below:
grocery_list = {cheese: 3, eggs: "dozen", steak: 1} grocery_list[:cheese] => 3By passing the key to the hash grocerylist, we will get the value of cheese in return. JavaScript has a similar notation but on top of that also has dot notation to access items in an Object Literal:
var myGroceryList = { cheese = 3, eggs = "dozen", steak = 1, }; myGroceryList[cheese] => 3 myGroceryList.cheese => 3These two different ways of accessing the same item in the object literal have their own advantages and disadvantages that you can read more about here.