0

I am trying to figure out a way to add field names and values to an object.

for example I hav ethe following...

$scope.product = {
        "Requirements": [
            {
                "OriginPostcode": '',
                "BearerSize": 100,
                "BandwidthRequired": 10
            }
        ]
   }

And I want to add two more names and values...

 "Term": 36,
 "Quantity": 1

I know the push() function is for arrays. What do you uses for objects?

Many thanks

Jose the hose
  • 1,805
  • 9
  • 33
  • 56

1 Answers1

2

You can use baces passing index like an array:

  $scope.product["Requirements"][0]["Term"] = 36
  $scope.product["Requirements"][0]["Quantity"] = 1

you can also do in this way

   $scope.product["Requirements"][0].Term = 36
   $scope.product["Requirements"][0].Quantity = 1

and also...

   $scope.product.Requirements[0].Term = 36
   $scope.product.Requirements[0].Quantity = 1

What do you need to understand is how to go through a javascript object using braces [] or point . Take a look at this link

nanndoj
  • 6,580
  • 7
  • 30
  • 42