push an item to top of object javascript 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: add key vakue to front of object

let obj = {'b': 2, 'c': 3};
Object.assign({a: 1}, obj);

// Object {a: 1, b: 2, c: 3}

Tags:

Php Example