E
E
emilkarussia2015-11-04 15:41:49
JavaScript
emilkarussia, 2015-11-04 15:41:49

Is it possible to create a variable from user-written data about it?

How to create a variable from user input? For example
var [user-entered variable name] = [user-entered variable value]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2015-11-04
@emilkarussia

var a = 'varname';
var str = a+' = '+'123';
eval(str)
alert(varname);

S
sunrails, 2015-11-04
@sunrails

var customerInput = [];
customerInput[varName] = varValue;

A
Alexey Ukolov, 2015-11-04
@alexey-m-ukolov

jsfiddle.net/koceg/uryrvos5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question