JavaScript JSON Array Numbers Are Inconsistent -


i have json includes array each key. of time, when access number leading zero, returns number integer. (this expect.)

when try access number 0400 through 0577 (inclusive) returns number seems relative 256.

can me understand why happens range of numbers?

var pricelist = {     "1":['product 1',0400, 1375,0200],     "2":['product 2',0425, 0599,0200],     "3":['product 3',0399, 0579,0200] }  alert(pricelist[1][1]);   // expect alert 400 -- actual alert: 256 alert(pricelist[2][1]);   // expect alert 420 -- actual alert: 277 alert(pricelist[3][1]);   // expect alert 399 -- actual alert: 399 

assuming mean json , not javascript object literal syntax, have not legal json since contains leading 0 in number disallowed in json. legal json, consider,

{      "1": ["product 1", 400, 1375, 200],      "2": ["product 2", 425, 599, 200],      "3": ["product 3", 399, 579, 200]  } 

remember, json subset of javascript object literal syntax.

if did mean object literal syntax, , not json specifically, leading 0 in numeric literal interpreted javascript octal number, not decimal number seem expect. 1 of reasons json forbids leading 0 ban octal encoding in json data avoid type of confusion.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -