0

I have an object defined as

myObject = {
  property1 : "",
  property2 : ""
}

I need to create an Array of the above object. I have tried using

myArray = myObject[].

But it doesn't seem to work.Is there any way that we can create an array of a predefined object in javascript.

6
  • 1
    What do you want to be stored in the array. Commented Sep 5, 2017 at 15:14
  • I'd maybe take a step back and check out a JS tutorial rather than trying to invent syntax--might be more efficient. Commented Sep 5, 2017 at 15:15
  • @MrGeek ... Instances of myObject like he said. Commented Sep 5, 2017 at 15:15
  • This is not a duplicate to that post Commented Sep 5, 2017 at 15:18
  • What result do you expect? Something like var myArray = ["", ""], or var myArray = [{property1 : "", property2 : ""}], or something else? Commented Sep 5, 2017 at 15:18

1 Answer 1

1
Is there any way that we can create an array of a predefined object in javascript?

No, in JavaScript, you can't type the content of your array at the declaration of your array.

What you are looking for is TypeScript.

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

1 Comment

Bad news!! Thanks anyways

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.