tags:

views:

109

answers:

3

In my Script.js I am trying to push the object to array=>array of objects.

$("#save_filter").click(function(){
    var filter_saved = new Object();//Create new object to store the filter have been saved.
    var customer_type_selected = $('#id_customer_type :selected').text();
    var list_tag_selected = $("#tag_checked").val();
    var filter_name = $("#put_filter_name").val();

    // Save filter name to the object={tag:[2,3,], customer_type:'TDO', more...}
    filter_saved = {
        customer_type: customer_type_selected,
        tag: list_tag_selected
    };
    var array_obj_filter_saved = []

    //I am trying...
    array_obj_filter_saved.push(filter_saved);//push every objects to array
    alert(array_obj_filter_saved.length);
});

My Array will be like this assciated array

array_obj_filter_saved = {"time1":filter_saved1,"time2":filter_saved2}

Anybody know how can I push every object to a array or associated array?

* filter_saved this an object it will create every time base on options in form(customer_type_selected(choicefield),list_tag_selected(checkboxs))

+1  A: 

Just like this:

var x= { a: 1};
x.b = 2;
eWolf
+1  A: 

This is very unclear to me. Is array_obj_filter_saved an array or not?

If you want to append all the elements of an Array to another Array, you can use the concat method:

var a1 = ["a", "b", "c"], a2 = ["d", "e"];
var a3 = a1.concat(a2); // a3 is ["a", "b", "c", "d", "e"]
Tim Down
yes it is an array.
python
I updated my question. thanks
python
+2  A: 

The line below is not an array, it is an object. You can only have integer indexes in arrays, and you use [] to define an array (like you did in your example).

array_obj_filter_saved = {"time1":filter_saved1,"time2":filter_saved2}

You cannot push objects onto an object, instead you set them, using the specific index:

array_obj_filter_saved["keyName"] = "value";
Marius