copy partial object in javascript code example
Example 1: move items from one log to another typescript
var array1 = [1, 2, 3, 4, 5];
var array2 = [];
for(var i = 0; i < array1.length; i++) {
array2.push(array1[i]);
array1.splice(i, 1);
i--; //decrement i IF we remove an item
}
console.log(array1); //[]
console.log(array2); //[1, 2, 3, 4, 5]
Example 2: javascript object get subset
const object = { a: 5, b: 6, c: 7 };const subset = (({ a, c }) => ({ a, c }))(object);console.log(subset); // { a: 5, c: 7 }