-3

I know this piece of code is wrong, but I wonder if there is any way this would be possible.

var createVariableFromParameter = function(myName) {

  var myName = [];
  return myName;
}

Thank you.

EDIT: I found the solution here: Convert string to variable name in Javascript

Community
  • 1
  • 1
luisfer
  • 603
  • 2
  • 8
  • 15

2 Answers2

0

I think it's not possible, and even if it could be done, why would you want to do it? There is no meaning in creating variables with random names...

0

I don't know why you should need it?? But I think true way is :

function create(myvar) { myvar = [];}

var a;
create(a);

function create() { return [];}

var b = new create();