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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -