MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiyoiu1/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
5
Adding attr/val to an object if condition is true
{
...(YOUR_CONDITION && { OBJ_KEY: OBJ_VAL })
}
1 u/wthit56 Mar 20 '19 What is that adding it to? Would it not just create an object within that conditional? 1 u/[deleted] Mar 20 '19 Presumably you're spreading it into an object with other properties already existing 1 u/wthit56 Mar 20 '19 Interesting. What would that code look like? → More replies (2)
1
What is that adding it to? Would it not just create an object within that conditional?
1 u/[deleted] Mar 20 '19 Presumably you're spreading it into an object with other properties already existing 1 u/wthit56 Mar 20 '19 Interesting. What would that code look like? → More replies (2)
Presumably you're spreading it into an object with other properties already existing
1 u/wthit56 Mar 20 '19 Interesting. What would that code look like? → More replies (2)
Interesting. What would that code look like?
→ More replies (2)
5
u/Thlemaus Mar 19 '19
Adding attr/val to an object if condition is true
{
...(YOUR_CONDITION && { OBJ_KEY: OBJ_VAL })
}