'How can i made an associative array with a variable? [duplicate]

How can i made an associative array with a variable?

var name = "example";
var array = [];
array.push(name: 1);

I want see in to the array example: 1

~Thank you everyone~



Solution 1:[1]

An object would fit the bill:

var key = "example";
var value = 1;
var dict = {};
dict[key] = value;

Solution 2:[2]

You can use:

var name = "example";
var array = [];
array[name] = 1;
console.log(array[name])

Or directly:

var name = "example";
var array = { name: 1};
console.log(array[name])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Victor