Home > Blockchain >  Set multiple properties at the same time instead of line by line
Set multiple properties at the same time instead of line by line

Time:11-11

Consider:

const obj = {
  w: true,
  a: true,
  s: true,
  d: true
};

Can we set all properties at once without repeating true every line ?

And not something like this:

let obj = {};
obj.a = obj.w = obj.d = obj.w = true;

CodePudding user response:

Here's one way using Object.fromEntries

  • Related