1

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

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Justin Abodo
  • 35
  • 1
  • 6
  • Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan Feb 08 '22 at 12:35
  • thanks you sir, I understood very well – Justin Abodo Feb 08 '22 at 15:07

1 Answers1

1

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}})
gil
  • 2,388
  • 1
  • 21
  • 29