prototypejs - How do I create a Hash from an Array using the Prototype JavaScript framewor? -
i've array ['red', 'green', 'blue']
i want create new hash array, result should be
{'red':true, 'green':true, 'blue':true}
what best way achieve goal using prototype?
just iterate on array , create hash:
var obj = {}; for(var = 0, l = colors.length; < l; i++) { obj[colors[i]] = true; } var hash = new hash(obj);
you can create new hash object beginning:
var hash = new hash(); for(var = 0, l = colors.length; < l; i++) { hash.set(colors[i], true); }
i suggest have @ documentation.
Comments
Post a Comment