Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, your Javascript code is invalid, perhaps you meant </p> <pre><code>var Salary = { "2012_08":"5555", "2012_09":"6666", "2012_10":"7777" } var augsalary = salary.2012_08; </code></pre> <p>Second, an all too common confusion is to talk of JSON objects. <code>Salary</code> is NOT a JSON object, it is a JavaScript object. JSON is a notation for expressing a large subset of all JavaScript objects as strings. These strings can then be transmitted to other parts of your code or other computers where they can be converted back into objects for processing. So in you question <code>Salary</code> would be data converted from a received JSON string.</p> <p>JS has arrays and objects. </p> <p>Objects are the most basic, they can have properties whose names can be any arbitrary string. Two forms of object property access is provided : brace and dot notation. Brace notation is universal, you specify the property name value as a string or variable value inside braces after the object name. Dot notation is a shorthand and can be used only when the name of the property has the form of a valid JS variable name.</p> <p>Arrays are basic objects which have the additional feature of maintaining an ordered list of their numeric property names. You can add non numeric property names to arrays but they do not participate in any Array function.</p> <p>So in you example you do not have numeric keys or property names since they contain a '_' character. Since they start with a digit you cannot use dot notation and must use the brace notation to access them as explained by <a href="https://stackoverflow.com/users/263525/dystroy">dystroy</a> below.</p> <p>Hoping my little lesson helps you better understand the basics.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload