2

I'm trying to push two whole arrays into one array.

The two arrays are named "quiz" and "t", how do I push them into "canvas"? Am I totally out of logic here or what am I missing? :)

var canvas = {};

canvas.push({
    QuizModule: quiz,
    Elements: t
    });

json_elements = JSON.stringify({Elements: canvas }, null, "\t");

2 Answers 2

5

It should be [] not {}. Push is applied on the array [] not on object {}.

var canvas = [];

canvas.push({
    QuizModule: quiz,
    Elements: t
    });
Sign up to request clarification or add additional context in comments.

Comments

0

push() is a function for Arrays, not Objects.

If you want to keep canvas as an Object, you could use extend() from Underscore.js (http://underscorejs.org/#extend):

_.extend(canvas, { QuizModule: quiz, Elements: t });

jQuery extend() would to the same.

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.