How To Create Or Get Values From Array Object Using JSON in Javascript?

JSON_LOGO

Today, i am going to  tell  how to use array Object Using JSON in Javascript. In below example, an object (JSONObject) is created containing two members java and json. First member java, which  contains an array containing two objects, each containing name and  price members. Second member json, which contains an array containing two objects, each containing name and  price members.

Example:
var JSONObject = {
"java": [
{"name": "learn java", "price": 500},
{"name": "easy java", "price":400}
],

"json":[
{"name": "learn javaScript", "price": 300},
{"name": "easy javaScript", "price":200}
]
};

java Members can be retrieved using dot or subscript operators easily.
JSONObject.java[0].name       // output: learn java
JSONObject.java[0].price       // output: 500

JSONObject.java[1].name       // output: easy java
JSONObject.java[1].price       // output: 400

json Members can be retrieved using dot or subscript operators easily.
JSONObject.json[0].name       // output: learn javaScript
JSONObject.json[0].price       // output: 300

JSONObject.json[1].name       // output: easy javaScript
JSONObject.json[1].price       // output: 200

Check running example here:
http://jsfiddle.net/jeetu_verma11/7D8jz/
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment