1let array = ["A", "B"];
2let variable = "what you want to add";
3
4//Add the variable to the end of the array
5array.push(variable);
6
7//===========================
8console.log(array);
9//output =>
10//["A", "B", "what you want to add"]
1let obj = {};
2let objToAdd1 = { prop1: "1", prop2: "2" };
3let objToAdd2 = { prop3: "3", prop4: "4" };
4
5// obj variabile could be empty or not, it's the same
6obj = { ...obj, ...objToAdd1 };
7obj = { ...obj, ...objToAdd2 };
8
9// Note that i used the spread operator... This syntax is available
10// only for the most recent js ES (from ES6 on, if i'm not wrong) :)
11
12console.log(obj);
1//push in object javascript
2var data = [];
3// ...
4data[0] = { "ID": "1", "Status": "Valid" };
5data[1] = { "ID": "2", "Status": "Invalid" };
6// ...
7var tempData = [];
8for ( var index=0; index<data.length; index++ ) {
9 if ( data[index].Status == "Valid" ) {
10 tempData.push( data );
11 }
12}
13data = tempData;
1var data = [];
2// ...
3data[0] = { "ID": "1", "Status": "Valid" };
4data[1] = { "ID": "2", "Status": "Invalid" };
5// ...
6var tempData = [];
7for ( var index=0; index<data.length; index++ ) {
8 if ( data[index].Status == "Valid" ) {
9 tempData.push( data );
10 }
11}
12data = tempData;
13
1var data = [];
2// ...
3data[0] = { "ID": "1", "Status": "Valid" };
4data[1] = { "ID": "2", "Status": "Invalid" };
5// ...
6var tempData = [];
7for ( var index=0; index<data.length; index++ ) {
8 if ( data[index].Status == "Valid" ) {
9 tempData.push( data );
10 }
11}
12data = tempData;