i was seeking for a solution like this in stackoverflow and in google but this is
the idea
a = {
b: (conditionB? 5 : undefined),
c: (conditionC? 5 : undefined),
d: (conditionD? 5 : undefined),
e: (conditionE? 5 : undefined),
f: (conditionF? 5 : undefined),
g: (conditionG? 5 : undefined),
};
but i dont understand this… it doesnt work in nodejs i want to create an
object a with many objects inside but if that objects are in the form send
by the client
This can be achieved in 2 ways.
Either you use an if sentence for each conditional property as such:
Or if you don’t want to create an if sentence for every property then you assign properties using the notation you presented in the question and then remove unnecessary ones in a loop: