-1

Maybe I'm tired, but I'm having trouble with something.

I need structure an array so it looks like:

{period:'2010-01',revenues:2000},{period:'2010-02',revenues:2200},....

I have this so far:

var data = {period:key,revenues:amount};

Which is in a jQuery.each function and works fine, but I cannot figure out how to put each iteration of data into an array that is structured like above.

I've tried:

dataArray += data;

dataArray.push(data); (this doesn't work because I can't have the keys)

1 Answer 1

1

You have an object {}. This is an array: []. What you can do is push the objects into an array:

    var myArr = [];
    var myData = {'key':'value'};
    myArr.push(myData);
    console.log(myArr);

Sign up to request clarification or add additional context in comments.

Comments

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.