how to push object in array in javascript code example

Example 1: js add item to array

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

Example 2: how to add objects in array

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

Example 3: push object into array javascript

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

Example 4: how to append objects to javascript lists ?

var studentList = ['Jason', 'Samantha', 'Alice', 'Joseph'];

//Add a new student to the end of the student list
studentList.push('Jacob');
//list is updated to ['Jason', 'Samantha', 'Alice', 'Joseph', 'Jacob'];

Example 5: how to add object to array javascript

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

array.push(object)

Example 6: how to push in object in 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;

Tags:

Java Example