Random78952
Random78952

Reputation: 1640

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

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 !

Upvotes: 0

Views: 480

Answers (2)

Chris Moutray
Chris Moutray

Reputation: 18349

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

Upvotes: 1

xdazz
xdazz

Reputation: 160833

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

var Arguments = {pages: []};

Upvotes: 2

Related Questions