0

I have this:

[Object]
  0:Object
    zipCode:"1232"

Now what i want is to get zipCode from object i tried with this:

Object[0].zipCode but i get message that 0 is undefined

Update:

 this.restService.getByParam("findAddress", customerId)
                    .subscribe(results =>   {
                    this.address = results.payload;
                });

And then i get that object and now i want to do something like this:

console.log(this.address[0].zipCode
None
  • 8,817
  • 26
  • 96
  • 171

2 Answers2

1

var obj = { 0 : {'zipCode':"1232"} }

for(var key in obj) {
  console.log(obj[key].zipCode);
}
sumit chauhan
  • 1,270
  • 1
  • 13
  • 18
0

here u go :

var foo = { 0 : {'zipCode':"1232"} }

for(var key in foo) {
var value = foo[key];
}

console.log(value); // this give you 'zipCode':"1232"
console.log(value['zipCode']); // this give you "1232"

https://jsfiddle.net/emilvr/9d58ebuy/

Emad Dehnavi
  • 3,262
  • 4
  • 19
  • 44