V
V
Vladimir Golub2018-03-14 12:43:41
JavaScript
Vladimir Golub, 2018-03-14 12:43:41

How to loop through all the properties of an object in an array?

data: function () {
          return {
           address: [
              {
                flat: 0,
                house: 0,
                street: 0,
                settlements: 0,
                municipality: 0,
                edge: 0
              },
              {
                flat: 0,
                house: 0,
                street: 0,
                settlements: 0,
                municipality: 0,
                edge: 0
              }
            ]
    }
},
methods: {
          paintLine() {
            for(var prop in this.address[0]) {
                console.log(prop + ':' + this.address[0].prop);
            }
          }
}

Displays all undefined values. How to fix ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2018-03-14
@RazerVG

Obviously, you are trying to get the 'prop' field from the object. upd. Don't forget to check if these are private properties of the object (hasOwnProperty)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question