Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js
const x = {one: 1, two:2}

An object in JavaScript is essentially an associative array
const x = new Map([["one",1],["two",2]]);

The Map constructor can take an array of [key, value] pairs.
const x = new Map();
x.set("one", 1);
x.set("two", 2);

From ES2015
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;

use Ada.Containers;
declare
   package Maps is new Indefinite_Hashed_Maps (Key_Type => String,
                                               Element_Type => Integer,
                                               Hash => Ada.Strings.Hash,
                                               Equivalent_Keys => "=");
      
   use Maps;
      
   X : Map := Empty_Map;
begin
   X.Insert ("One", 1);
   X.Insert ("Two", 2);
   X.Insert ("Three", 3);
end;

New implementation...