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

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

Rendyon | 3:36 AM | 0 comments

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 this article :

0 comments:

 
Copyright © 2011. Find Updates - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger