Tambahkan properti ke objek secara kondisional
// Add Propperties to an object conditionally.
const isOnline = true;
const user = {
id: 1,
name: 'John',
...(isOnline && { active: true }),
}
console.log(user);
// { id: 1, name: 'John', active: true }
The Ultimate Karam