Assign a user input string as a new variable name in javascript -
i have text field in user inputs text. i'd take first word of text , turn global variable name object holding rest of string content. more string content added object later, internal indexing inside object required.
var textinput = $('#inputtext').val(); var splitstring = textinput.split(" "); var firstword = splitstring[0];
this stuck. how please create new object string referenced firstword object's reference?
many in advance.
i try this:
globaluserobjects = {}; var textinput = $('#inputtext').val(); var splitstring = textinput.split(" "); var firstword = splitstring[0]; globaluserobjects[firstword] = {}; // later can add stuff globaluserobjects[firstword]["firstname"] = "john"; globaluserobjects[firstword]["lastname"] = "smith";
Comments
Post a Comment