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

I want to add many object inside a nested array of object with a specific key in javascript

I want to add one or many objects inside an array of object which a specific key whose structure has been shown below.

Help would be appreciated

structure:

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

{
  "nameEn": "string",
  "nameFr": "string",
  "descriptionFr": "string",
  "descriptionEn": "string",
  "code": "string",
  "permissions": [
    {
      "endUI": "string"
    },
    {
      "endUI": "string"
    }
  ]
}

here is what I did but it gives me something else:

let data = {
          nameEn: this.dataForm.nameEn,
          nameFr: this.dataForm.nameFr,
          descriptionFr: this.dataForm.descriptionFr,
          descriptionEn: this.dataForm.descriptionEn,
          code: this.dataForm.code,
          permissions:  [
            {
              "endUI": this.dataForm.endUI
            }
          ]
        }

And this is the result:

enter image description here

>Solution :

it seems like this.dataForm.endUI is a list so
you probably want to map it like this:

permissions:  this.dataForm.endUI.map((elm) => {return {endUI: elm}})
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