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.

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

Leave a Comment