0

How to add a value in a json subarray with jQuery ?

I has build this code but it dosen't work... The developer console tell me "Cannot call method 'push' of undefined"

function save(){
 var Arguments = [];
 $('.builder-page').each(function(){
 var title = $(this).find('input[name=title]').val();
 Arguments.pages.push({'title':title})
 });
 console.log(Arguments);
}

Thanks !

asked Sep 8, 2012 at 9:43

2 Answers 2

2

You need to declare it as on object which has an array as its pages property.

var Arguments = {pages: []};
answered Sep 8, 2012 at 9:47
1

Arguments is your array not pages. There's no indication in your code that pages is every created...

answered Sep 8, 2012 at 9:47
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.