push to array of objects javascript code example

Example 1: js push array

var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]

Example 2: how to add objects in array

var a=[], b={};
a.push(b);    
// a[0] === b;

Example 3: push in object javascript

//push in object javascript
var data = [];
// ...
data[0] = { "ID": "1", "Status": "Valid" };
data[1] = { "ID": "2", "Status": "Invalid" };
// ...
var tempData = [];
for ( var index=0; index<data.length; index++ ) {
    if ( data[index].Status == "Valid" ) {
        tempData.push( data );
    }
}
data = tempData;

Example 4: push object into array javascript

var nietos = [];
var obj = {};
obj["01"] = nieto.label;
obj["02"] = nieto.value;
nietos.push(obj);

Example 5: how to add object to array javascript

var object = "Some Object"
var array = []

array.push(object)

Example 6: javascript array push object

var myArray = [];
myArray.push("Example");
myArray.push("text");