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

Time:02-08

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:

{
  "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

CodePudding user response:

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}})
  •  Tags:  
  • Related