js create disctionary in javascript in javascript

index.tsx
// You can create a dictionary (object) in JavaScript like this:
let dictionary = {
    key1: "value1",
    key2: "value2",
    key3: "value3"
};

// You can also add or update key-value pairs in the dictionary like this:
dictionary["newKey"] = "newValue";

// Access a value in the dictionary like this:
console.log(dictionary["key1"]); // Output: value1

// To loop over the dictionary, you can use for..in loop:
for (let key in dictionary) {
    console.log(key + ": " + dictionary[key]);
}
494 chars
18 lines

related categories

gistlibby LogSnag