Convert array of strings into an object with those string as properties and null values

Let’s say I have this:

const myArr = ["NAME_A","NAME_B","NAME_C"];

And I’d like to convert it to:

const myObj = {
  NAME_A: null,
  NAME_B: null,
  NAME_C: null,
}

I can do it by initializing an empty object and adding properties by iterating the array with forEach or something, but I believe there is a more efficient solution out there.

87 thoughts on “Convert array of strings into an object with those string as properties and null values”

  1. 848041 129666Aw, this really is an incredibly nice post. In thought I would like to put in location writing like this moreover – spending time and actual effort to create a great article but exactly what do I say I procrastinate alot by means of no indicates seem to get something accomplished. 568717

    Reply

Leave a Comment