add object to array method code example

Example 1: 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 2: 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'];

Tags:

Php Example