Q:

Best way to store a key=>value array in JavaScript?

What's the best way to store a key=>value array in javascript, and how can that be looped through?
The key of each element should be a tag, such as {id} or just id and the value should be the numerical value of the id.
It should either be the element of an existing javascript class, or be a global variable which could easily be referenced through the class.
jQuery can be used.

A:

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]);
}

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.

A:

If I understood you correctly:
var hash = {};
hash['bob'] = 123;
hash['joe'] = 456;

var sum = 0;
for (var name in hash) {
    sum += hash[name];
}
alert(sum); // 579

A:

You can use Map.

A new data structure introduced in JavaScript ES6.
Alternative to JavaScript Object for storing key/value pairs.
Has useful methods for iteration over the key/value pairs.

var map = new Map();
map.set('name', 'John');
map.set('id', 11);

// Get the full content of the Map
console.log(map); // Map { 'name' => 'John', 'id' => 11 }

Get value of the Map using key
console.log(map.get('name')); // John 
console.log(map.get('id')); // 11

Get size of the Map
console.log(map.size); // 2

Check key exists in Map
console.log(map.has('name')); // true
console.log(map.has('age')); // false

Get keys
console.log(map.keys()); // MapIterator { 'name', 'id' }

Get values
console.log(map.values()); // MapIterator { 'John', 11 }

Get elements of the Map
for (let element of map) {
  console.log(element);
}

// Output:
// [ 'name', 'John' ]
// [ 'id', 11 ]

Print key value pairs
for (let [key, value] of map) {
  console.log(key + " - " + value);
}

// Output: 
// name - John
// id - 11

Print only keys of the Map
for (let key of map.keys()) {
  console.log(key);
}

// Output:
// name
// id

Print only values of the Map
for (let value of map.values()) {
  console.log(value);
}

// Output:
// John
// 11

