JailBreakRex JailBreakRex - 1 month ago 7
Javascript Question

How can show a someone data in JSON on javascript?

var example = {
"Equation" : [{
"name" : "My Equation",
"xMin" : [41901.0840,4,3,5,2],
"yMin" : [0.0000,4,5,7,8,9,3,1]
}
]
};

var e = JSON.parse(example);

alert(e.example.xMin);


/* What's the problem, can't show any data on array object, at least xMin is Array, how can show someone number on array. Thanks!. */

Answer

There is no need to parse since it's already a valid object. To get the property you need to get the Equation property and then it's the first element afterward get xmin property.

var example = {
  "Equation": [{
    "name": "My Equation",
    "xMin": [41901.0840, 4, 3, 5, 2],
    "yMin": [0.0000, 4, 5, 7, 8, 9, 3, 1]
  }]
};


alert(example.Equation[0].xMin);

Comments