0

Hi I am new to jquery

var sales = [{CategoryName="colddrink",ProductName="coke", SaleMonth="Feb ",    CategoryId=1},
{ CategoryName="colddrink",ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1}     {CategoryName="Snacks", ProductName="nuts",SaleMonth="Dec", CategoryId=32},
         {CategoryName="colddrink",ProductName="pepsi", SaleMonth="Mar ", CategoryId=1},
         {CategoryName="Snacks",ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]

and that is what I am looking for

var sales = { "colddrink" :[{ProductName="coke", SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi" ,SaleMonth="Feb ", CategoryId=1},
            {ProductName="pepsi", SaleMonth="Mar ", CategoryId=1}],

    "Snacks"  :[{ProductName="nuts",SaleMonth="Dec", CategoryId=32},
            {ProductName="popcorn", SaleMonth="Feb ", CategoryId=32}]
    }

Is it possible in jquery?

1

2 Answers 2

1

Nested objects?

var sales = {
    cooldrink : {
        productname: 'coke',
        salemonth: 'feb'
    },
    snacks: {
        productname: 'nuts',
        salemonth: 'dec'
    }
};

alert(sales.cooldrink.productname);​ //coke
Sign up to request clarification or add additional context in comments.

Comments

0

It's not really jQuery, though jQuery use JSON most of the time, but this one is simply JSON, an object in Javascript. Just create a function which can sort things out. In fact, you don't need any jQuery at all for this type of job.

1 Comment

There are important differences between JSON and JavaScript objects (namely Object literal syntax); stackoverflow.com/questions/8294088/javascript-object-vs-json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.