Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  82] [ 1]  / answers: 1 / hits: 16203  / 8 Years ago, tue, march 1, 2016, 12:00:00

Id like to get the first returned value of data.countrys model as below :



...el ...etc..

data: {

countrys: [
{KE : 'KENYA'},
{USA : 'USA'}

] ,


},
... ready...etc..


How can i get the value 'KE' in my method ? below is code am using in my method .



console.log(vm.$data.$children[0].countrys);


More From » vue.js

 Answers
21

Since 'KE' is a key, you can use Object.keys function on the object within the 'countrys' array:



Object.keys(vm.data.countrys[0])[0];


vm.data.countrys[0] will return the {KE : 'KENYA'} object, and then Object.keys will return an array of keys of that object.


[#63096] Sunday, February 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darleneh

Total Points: 231
Total Questions: 110
Total Answers: 94

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;