Home > Net >  Convert simple array into array of objects and add new property
Convert simple array into array of objects and add new property

Time:08-05

I have an array

const databaseName = ['Oracle','Mysql','MongoDb'];

the expected output is

const database = [
{
  name:'Oracle',
  isAvailable:true
},
{
  name:'Mysql',
  isAvailable:true
},
{
  name:'MongoDb',
  isAvailable:true
}
]

This has to be done using Javascript and es6.

i have tried using

const database = {...databaseName ,isAvailable:true}

CodePudding user response:

const databaseName = ['Oracle','Mysql','MongoDb'];

console.log(
  databaseName.map(name => {
    return {
      name,
      isAvailable:true
    }
  })
)

  • Related