A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/flesler/hashmap below:

flesler/hashmap: HashMap JavaScript class for Node.js and the browser. The keys can be anything and won't be stringified

HashMap Class for JavaScript

Using npm:

Using bower:

You can download the last stable version from the releases page.

If you like risk, you can download the latest master version, it's usually stable.

To run the tests:

This project provides a HashMap class that works both on Node.js and the browser. HashMap instances store key/value pairs allowing keys of any type.

Unlike regular objects, keys will not be stringified. For example numbers and strings won't be mixed, you can pass Date's, RegExp's, DOM Elements, anything! (even null and undefined)

HashMap constructor overloads

All methods that don't return something, will return the HashMap instance to enable chaining.

Assume this for all examples below

If you're using this within Node, you first need to import the class

var HashMap = require('hashmap');
map.set("some_key", "some value");
map.get("some_key"); // --> "some value"
Map size / number of elements
var map = new HashMap();
map.set("key1", "val1");
map.set("key2", "val2");
map.size; // -> 2
map.set("some_key", "some value");
map.delete("some_key");
map.get("some_key"); // --> undefined
map.set("1", "string one");
map.set(1, "number one");
map.get("1"); // --> "string one"

A regular Object used as a map would yield "number one"

var key = {};
var key2 = {};
map.set(key, 123);
map.set(key2, 321);
map.get(key); // --> 123

A regular Object used as a map would yield 321

map.set(1, "test 1");
map.set(2, "test 2");
map.set(3, "test 3");

map.forEach(function(value, key) {
    console.log(key + " : " + value);
});
// ES6 Iterators version
for (const pair of map) {
    console.log(`${pair.key} : ${pair.value}`)
}
map
  .set(1, "test 1")
  .set(2, "test 2")
  .set(3, "test 3")
  .forEach(function(value, key) {
      console.log(key + " : " + value);
  });

The MIT License (MIT)

Copyright (c) 2012 Ariel Flesler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4