Prev: FAQ Topic - How do I format a Date object with javascript? (2010-07-26)
Next: Multiple Select validation with jquery
From: FAQ server on 4 Aug 2010 19:00 ----------------------------------------------------------------------- FAQ Topic - When should I use eval? ----------------------------------------------------------------------- The `eval` function should _only_ be used when it is necessary to evaluate a string supplied or composed at run-time; the string can be anything from a simple (but unpredictable) expression such as `"12 * 2.54"` to a substantial piece of javascript code. When `eval( '{"key" : 42}' )` is called, `{` is interpreted as a block of code instead of an object literal. Hence, the Grouping Operator (parentheses) is used to force `eval` to interpret the JSON as an object literal: `eval( '({"key" : 42})' );`. <URL: http://json.org/> How do I access a property of an object using a string? [ref 1] <URL: http://jibbering.com/faq/notes/square-brackets/> References: ----------- [1] http://jibbering.com/faq/#propertyAccessAgain The complete comp.lang.javascript FAQ is at http://jibbering.com/faq/ -- The sendings of these daily posts are proficiently hosted by http://www.pair.com. |