which of this approach is better?

1)
const { password, ...userWithoutPassword } = user;
return userWithoutPassword
const { password, ...userWithoutPassword } = user;
return userWithoutPassword
2)
delete user.password;
return user
delete user.password;
return user
2 Replies
Matvey
Matvey15mo ago
The first one copies the user object, creating new memory. The second one modifies the object, without any new allocations. From a performance standpoint, the second one is better. But the first one is more intuitive
Lopen
LopenOP15mo ago
what would you use? or do you have a better suggestion?
Want results from more Discord servers?
Add your server