1

i have this array:

const array = [ 'one', 'two', 'three' ]

I'd like to convert this array into an object without indexes. How would this be possible?

Timo
  • 109
  • 1
  • 9

1 Answers1

2

Try with Array#forEach() .Iterate the array using foreach and append key and value with in res object

const array = [ 'one', 'two', 'three' ]
var res={}
array.forEach(function(a){
  res[a]=a
})
console.log(res)
prasanth
  • 21,342
  • 4
  • 27
  • 50