1var object = {'Name'};
2var array = [ ]; // Create empty array
3
4// SIMPLE
5 array.push(object); // ADDS OBJECT TO ARRAY (AT THE END)
6 // or
7 array.unshift(object); // ADDS OBJECT TO ARRAY (AT THE START)
8
9// ADVANCED
10 array.splice(position, 0, object);
11 // ADDS OBJECT TO THE ARRAY (AT POSITION)
12
13 // Position values: 0=1st, 1=2nd, etc.
14 // The 0 says: "remove 0 objects at position"
1const arr = ["foo", "bar"];
2arr.push('baz'); // 3
3arr; // ["foo", "bar", "baz"]
1var select =[2,5,8];
2var filerdata=[];
3for (var i = 0; i < select.length; i++) {
4 filerdata.push(this.state.data.find((record) => record.id == select[i]));
5}
6//I have a data which is object,
7//find method return me the filter data which are objects
8//now with the push method I can make array of objects
1let obj = { name: 'Bob' };
2let arr = [{ name: 'John' }];
3
4// add obj to array
5arr = [...arr, obj];
6
7console.log(arr) // [{ name: 'Bob' }, { name: 'John' }];