Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to change key and value of object?

how to change value of the object to an object contains key:value key:value to all models array
if there any way please share it with me

const hello = [
    {
      brand: "Acura",
      models: [
        "2.2CL",
        "2.3CL",
        "3.0CL",
        "3.2CL",
        "ILX",
        "Integra",
        "Legend",
        "MDX",
        "NSX",
        "RDX",
        "3.5 RL",
        "RL",
        "RSX",
        "SLX",
        "2.5TL",
        "3.2TL",
        "TL",
        "TSX",
        "Vigor",
        "ZDX"
      ]
    },
    {
      brand: "Alfa Romeo",
      models: [
        "164",
        "8C Competizione",
        "GTV-6",
        "Milano",
        "Spider"
      ]
    },
    {
      brand: "AMC",
      models: [
        "Alliance",
        "Concord",
        "Eagle",
        "Encore",
        "Spirit"
      ]
    },

and make it like this for all models {value:"value", label:"value"},

const hello = [
    {
      brand: "Acura",
      models: [
       {value:"2.2CL", label:"2.2CL"},
       {value:"2.3CL", label:"2.3CL"},
       .



       

and make it like this for all models {value:"value", label:"value"},and make it like this for all models {value:"value", label:"value"},and make it like this for all models {value:"value", label:"value"},

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is what you could do :

const hello = [{
    brand: "Acura",
    models: [
      "2.2CL",
      "2.3CL",
      "3.0CL",
      "3.2CL",
      "ILX",
      "Integra",
      "Legend",
      "MDX",
      "NSX",
      "RDX",
      "3.5 RL",
      "RL",
      "RSX",
      "SLX",
      "2.5TL",
      "3.2TL",
      "TL",
      "TSX",
      "Vigor",
      "ZDX"
    ]
  },
  {
    brand: "Alfa Romeo",
    models: [
      "164",
      "8C Competizione",
      "GTV-6",
      "Milano",
      "Spider"
    ]
  },
  {
    brand: "AMC",
    models: [
      "Alliance",
      "Concord",
      "Eagle",
      "Encore",
      "Spirit"
    ]
  },
];

const result = hello.map(item => {
  return {
    ...item,
    models: item.models.map(val => {
      return {
        value: val,
        label: val
      }
    })
  }
});

console.log(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading