javascript - Array creating using specific property of array of objects -


this question has answer here:

there array of objects follows. need create array using vatcode propery following array of objects without going through 'for loop'. here result should be
resultarray = [1, 15, 25]

"data": [     {         "id": 1,         "vatcode": 1,         "name": "ingen mva.",                     "vataccount": {             "id": 3,             "accountno": "3190",             "name": "misc items income"         }                 },     {         "id": 2,         "vatcode": 15,         "name": "lav mva.",                    "vataccount": {             "id": 3,             "accountno": "3190",             "name": "misc items income"         }     },     {         "id": 3,         "vatcode": 25,         "name": "høy mva.",                    "vataccount": {             "id": 3,             "accountno": "3190",             "name": "misc items income"         }     },  ] 

data = //your json data      this.data.map(data => data.vatcode); 

the map() method creates new array results of calling function every array element.

var data = [      {          "id": 1,          "vatcode": 1,          "name": "ingen mva.",                      "vataccount": {              "id": 3,              "accountno": "3190",              "name": "misc items income"          }                  },      {          "id": 2,          "vatcode": 15,          "name": "lav mva.",                     "vataccount": {              "id": 3,              "accountno": "3190",              "name": "misc items income"          }      },      {          "id": 3,          "vatcode": 25,          "name": "høy mva.",                     "vataccount": {              "id": 3,              "accountno": "3190",              "name": "misc items income"          }      },    ];    var s = data.map(data => data.vatcode);  console.log(s);


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -