simpleJsMap

A light weight Javascript implementation of maps


License
GPL-2.0
Install
bower install simpleJsMap#1.0.0

Documentation

simplejsmap

A light weight and simple Javascript implementation of maps

Getting Started

Include the simplejsmap.js file into your script. The variable simplejsmap would then be available.

<script src="//path/to/simplejsmap.js" type=”text/javascript”></script>
<script type=”text/javascript”>
// simplejsmap now available
</script>

I am a big fan of pure Javascript first before framework, thus simplejsmap is not dependent on any Javascript framework; not even jQuery :p

So once you have the script included you ready to go.

Function reference

createMap()

 var map = simplejsmap.createMap(); 

Creates the map like object and assigns it to variable map. You always start using simplejsmap by calling this function.

add(key, value)

var map = simplejsmap.createMap();
map.add("key1", "value one");

Adds stuff that needs to be kept. The stuff has a value and is associated with a key. Returns true if successfully added and false if not. If the key is already present, nothing happens and false is returned also. To modify the value of a key that is already added, update() function is used.

key and value can be of any Javascript type.

update(key, value)

var map = simplejsmap.createMap();
map.update("key1", "updated value");

Updates the value already added by a given key. If the given key exists, its value is updated. If the key is not found, no update operationis done. False is returned instead.

remove(key)

var map = simplejsmap.createMap();
map.remove(“key1”);

Removes a value accessible via the given key. If the given key is already in existence, it is removed and true is returned. If not, false is returned.

get(key)

var map = simplejsmap.createMap();
map.add(“key2”, “Hello World”);
var val = map.get(“key2”);

Gets the value stored via given key.

getLength()

var map = simplejsmap.createMap();
var len = map.getLength();

Returns the number of stuffs/keys that has been added.

getKeys()

var map = simplejsmap.createMap();
var keys = map.getKeys();

Returns all the keys that has been added as an array.