How to convert array object to arguments in javascript -



How to convert array object to arguments in javascript -

i have class this:

enum = function() { (var = 0, len = arguments.length; < len; i++) { var k= arguments[i]; this[k] = i; } object.freeze(this); };

to create enum of string, phone call : var options = new enum("eat","drink","sleep"); // many arguments

if have array of arguments stored in variable. ex: var arg_array = ["eat","drink","sleep"], how pass new enum(...)

use function.prototype.apply:

var = {}; enum.apply(a, ["eat","drink","sleep"]);

will give you:

{ "eat": 0, "drink": 1, "sleep": 2 }

javascript arrays arguments

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -