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

2
  • Please visit help center, take tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a minimal reproducible example of your attempt, noting input and expected output, preferably in a Stacksnippet Commented Feb 8, 2022 at 12:35
  • thanks you sir, I understood very well Commented Feb 8, 2022 at 15:07

1 Answer 1

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}})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.