QuickTip JavaScript
When dealing with many different objects in JavaScript, sometimes you need to compile them all down together. The spread operator is a handy function for this and more.
const veggies = { onions: 2, potatoes: 3 };
const fruits = { apples: 2, bananas: 4 };
const inventory = {...veggies, ...fruits};
/*
{ onions: 2, potatoes: 3, apples: 2, bananas: 4 }
*/
const user_list_1 = [232,567,344,74];const user_list_2 = [109,34,224,920];
const all_users = {...user_list_1, ...user_list_2};
/*
[
232, 567, 344, 74,
109, 34, 224, 920
]
*/
Similar Posts