Answers for "js object conditional key"

1

conditionally add key to object javascript

const condition = getCondition();
const additionalCondition = getAdditionalCondition();

const person = {
  firstName: "Max",
  ...(condition && { lastName: "" }),
  ...(additionalCondition && { addition: "" }),
};
Posted by: Guest on December-03-2020
4

js conditional object key

const object = {
  ...bool && { foo: 2 },
}
Posted by: Guest on January-13-2021

Code answers related to "js object conditional key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language