I want my user to input some text in an input field and click a button “Evaluate” on clicking that button I will convert that inputted text into a JavaScript object if I could and will show all of it’s members(properties and functions).
For example if user inputs "document" or "window" I will show all members of document and window respectively.
Iterating through the members of an object is done, but when user inputs some text in input text field and I get that text than that value is treated as String of course how can I convert that text into an object like "document" to document and "window" to window ???
You can use “eval”. Edit: Thanks to the comments of @Victor and @Cerbrus for pointing out that eval is unnecessary here. You can also use
window[input].If it’s a member of another object (ie, a global object), then you can use the bracket-notation: