-3

Suppose my JSON is:

{
  "todo" : "Dinner",
  "user" : [
    {
      "name" : "",
      "password" : ""
    }
  ],
  "notes : "some notes"
}

And I want to formulate the object from that JSON.

So in angularjs, first I can do the following to formulate the user array:

userArray = [{
                name: 'myname',
                password: 'password'
            }];

And my object without userArray is as follows:

var object = {};
object.todo = "Dinner";
object.notes = "some notes";

Now how to add userArray to this object to get the complete object?

sjain
  • 23,126
  • 28
  • 107
  • 185

1 Answers1

0

Just set the array to your scope object in the controller. Angular has nothing to do with this. Its plain JavaScript.

$scope.object.user = userArray;
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
Dennis Nerush
  • 5,473
  • 5
  • 25
  • 33
  • How to add the userArray dynamically in a loop? See my update. – sjain Feb 29 '16 at 13:15
  • 1
    @MyGod - probably best to ask a new question at this late stage, particularly since the question has now changed! – gtlambert Feb 29 '16 at 13:18
  • sure this is done here: http://stackoverflow.com/questions/35700686/adding-object-to-an-array-dynamically – sjain Feb 29 '16 at 13:23