That's just what a JavaScript object is:

var myArray = {id1: 100, id2: 200, "tag with spaces": 300};
myArray.id3 = 400;
myArray["id4"] = 500;

You can loop through it using for..in loop:

for (var key in myArray) {
  console.log("key " + key + " has value " + myArray[key]);
}

var myArray = {
  id1: 100,
  id2: 200,
  "tag with spaces": 300
};
myArray.id3 = 400;
myArray["id4"] = 500;

for (var key in myArray) {
  console.log("key " + key + " has value " + myArray[key]);
}

See also: Working with objects (MDN).

In ECMAScript6 there is also Map (see the browser compatibility table there):

  • An Object has a prototype, so there are default keys in the map. This could be bypassed by using map = Object.create(null) since ES5, but was seldomly done.

  • The keys of an Object are Strings and Symbols, where they can be any value for a Map.

  • You can get the size of a Map easily while you have to manually keep track of size for an Object.

Answer from Alexey Romanov on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_keys.asp
JavaScript Array keys() Method
The keys() method returns an Iterator object with the keys of an array.
🌐
Flexiple
flexiple.com › javascript › key-value-javascript
JavaScript: Obtain key-value pairs - Flexiple
Learn how to use JavaScript to obtain key-value pairs in an array efficiently. Get practical tips and examples for working with data structures.
🌐
W3Schools
w3schools.com › jsref › jsref_object_keys.asp
JavaScript Object.keys() Method
Object.entries() returns the keys and values of any object types. The methods above return an Iterable (enumerable array).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › keys
Array.prototype.keys() - JavaScript | MDN
The keys() method reads the length property of this and then yields all integer indices between 0 and length - 1. No index access actually happens. ... const arrayLike = { length: 3, }; for (const entry of Array.prototype.keys.call(arrayLike)) { console.log(entry); } // 0 // 1 // 2
🌐
W3Schools
w3schools.com › jsref › jsref_entries.asp
JavaScript Array entries() Method
❮ Previous JavaScript Array Reference Next ❯ · // Create an Array const fruits = ["Banana", "Orange", "Apple", "Mango"]; // Create an Iterator const list = fruits.entries(); // List the Entries let text = ""; for (let x of list) { text += x; } Try it Yourself » · More Examples Below! The entries() method returns an Iterator object with the key/value pairs from an array: [0, "Banana"] [1, "Orange"] [2, "Apple"] [3, "Mango"] The entries() method does not change the original array.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Object.keys, values, entries
... Plain objects also support similar methods, but the syntax is a bit different. For plain objects, the following methods are available: Object.keys(obj) – returns an array of keys.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-store-a-key-value-array-in-javascript
How to store a key=> value array in JavaScript ? - GeeksforGeeks
July 12, 2025 - Using the Objects approach in JavaScript, key-value pairs are stored in an object where each key is associated with a specific value. Objects are ideal for mapping keys to values and are versatile, handling various data types including numbers, ...
Find elsewhere
🌐
LearnersBucket
learnersbucket.com › home › examples › javascript › how to create key value array in javascript
How to create key value array in javascript - LearnersBucket
June 12, 2019 - Learn how to create a key value array in javascript. Use objects to create an associative array or use es6 map data structures.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › keys
Object.keys() - JavaScript | MDN
If you need both the property keys and values, use Object.entries() instead. ... // Basic array const arr = ["a", "b", "c"]; console.log(Object.keys(arr)); // ['0', '1', '2'] // Array-like object const obj = { 0: "a", 1: "b", 2: "c" }; console.log(Object.keys(obj)); // ['0', '1', '2'] // Array-like ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › entries
Object.entries() - JavaScript | MDN
Using array destructuring, you can iterate through objects easily. ... // Using for...of loop const obj = { a: 5, b: 7, c: 9 }; for (const [key, value] of Object.entries(obj)) { console.log(`${key} ${value}`); // "a 5", "b 7", "c 9" } // Using array methods Object.entries(obj).forEach(([key, value]) => { console.log(`${key} ${value}`); // "a 5", "b 7", "c 9" });
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript key value array
How to Store Key-Value Array in JavaScript | Delft Stack
March 11, 2025 - Discover various methods to store key-value arrays in JavaScript. This comprehensive guide covers objects, arrays of objects, and Maps, providing clear examples and explanations. Learn how to effectively manage data in your JavaScript projects and enhance your coding skills.
🌐
TutorialsPoint
tutorialspoint.com › how-to-store-a-key-value-array-in-javascript
How to store a key => value array in JavaScript?
We have used the map, object, and array.reduce() method to store the data in the key- value format in JavaScript.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Create an array of key-value pair arrays from a given object - JavaScript - The freeCodeCamp Forum
November 18, 2022 - Trying to understand the code [k, obj[k], here object.keys is taking keys of an object and map them so ‘k’ refers to ‘a’ and ‘b’ which are keys. obj[k] seems we are putting mapped keys ‘k’ in an object ‘obj’ to make an array but how we are getting values in an array then?
🌐
W3Schools
w3schools.com › js › js_json_objects.asp
W3Schools.com
JSON object literals contains key/value pairs.
🌐
Programiz
programiz.com › javascript › library › array › keys
JavaScript Array keys() (With Examples)
In this tutorial, you will learn about the JavaScript Array keys() method with the help of examples. The keys() method returns a new Array Iterator object that contains the keys for each element in the array.
🌐
W3docs
w3docs.com › learn-javascript › object-keys-values-entries.html
Mastering JavaScript: A Comprehensive Guide to Object Manipulation
Combining the power of keys and values, Object.entries(obj) returns an array of a given object's own enumerable string-keyed property [key, value] pairs.
🌐
Sentry
sentry.io › sentry answers › javascript › how can i add a key-value pair to a javascript object?
How Can I Add a Key-Value Pair to a JavaScript Object? | Sentry
You can use the spread (...) syntax to add a key-value pair to an object: ... const obj = { name: "Ben" }; const newObj = { ...obj, age: 22 }; console.log(newObj); // { name: 'Ben', age: 22 } You can spread in any iterable, such as an array, ...
🌐
Pitayan
pitayan.com › posts › javascript-key-value-array
Javascript key-value store: understand some cool built-in Objects | Pitayan Blog
July 2, 2020 - In this article, I’ll show you how to handle Javascript “key-value” data type with its special “Array”.
🌐
Medium
medium.com › design-bootcamp › understanding-key-value-️pairs-and-object-entries-️for-mapping-data-in-javascript-54c988bb33df
Understanding Key-Value 🗝️Pairs and Object Entries ⛩️for Mapping Data 📱in JavaScript | by Israel | Bootcamp | Medium
September 4, 2023 - Creating Key-Value Pairs: Creating ... associate them with values using colons. In arrays, each element has an index that can be considered a key, with the corresponding value....