0

I have an object "config" and an id "id", I would like to create an array of objects that has the following structure:

[
  "id" : {
          "config1: ...
          "config2: ...
          "config3: ...

         }
  "id2" : {
          "config1: ...
          "config2: ...
          "config3: ...

         }

]

I tried the following code:

garage.push( {this.id : this.config });

but it causes compiling errors such as:

ERROR in component.ts (168,51): An object literal cannot have multiple properties with the same name in strict mode.

How can I make this work?

6
  • 1
    How is garage declared? What is its type? Commented May 16, 2017 at 16:20
  • let garage = []; Commented May 16, 2017 at 16:22
  • 1
    "Compiling errors"? Can add these to your question? Commented May 16, 2017 at 16:23
  • added @evolutionxbox Commented May 16, 2017 at 16:24
  • Are you not also getting a SyntaxError? Commented May 16, 2017 at 16:31

1 Answer 1

4

you may try below,

let _temp = {};
_temp[this.id] = this.config;
garage.push(_temp);

Hope this helps!!

Sign up to request clarification or add additional context in comments.

1 Comment

Solves the syntax problems, but OP will still struggle with their "compile" error.

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.