gpt4 book ai didi

javascript - 来自对象和对象的名称数组

转载 作者:行者123 更新时间:2023-12-02 00:35:27 24 4
gpt4 key购买 nike

我有一个包含对象的对象,如下所示:

{
"AD": {
"name": "Andorra",
"native": "Andorra",
"phone": "376",
"continent": "EU",
"capital": "Andorra la Vella",
"currency": "EUR",
"languages": [
"ca"
]
},
"AE": {
"name": "United Arab Emirates",
"native": "دولة الإمارات العربية المتحدة",
"phone": "971",
"continent": "AS",
"capital": "Abu Dhabi",
"currency": "AED",
"languages": [
"ar"
]
},
"AF": {
"name": "Afghanistan",
"native": "افغانستان",
"phone": "93",
"continent": "AS",
"capital": "Kabul",
"currency": "AFN",
"languages": [
"ps",
"uz",
"tk"
]
}
}

现在我需要获取名称数组[“安道尔”,“阿拉伯联合酋长国”,“阿富汗”],以便我可以以这种格式将该值发送到选择字段:

<q-select color="teal" outlined v-model="model" :options="options" label="Label">
<template v-slot:append>
</template>
</q-select>

<script>
export default {
data () {
return {
model: null,

options: [
'Google', 'Facebook', 'Twitter', 'Apple', 'Oracle'
]
}
}
}
</script>

我尝试将对象转换为数组,但是当我尝试使用array.name访问时,这不起作用。我只需要从这个对象的对象中获取名称。有谁知道我该怎么做?

最佳答案

您可以获得值和名称属性。

var object = { AD: { name: "Andorra", native: "Andorra", phone: "376", continent: "EU", capital: "Andorra la Vella", currency: "EUR", languages: ["ca"] }, AE: { name: "United Arab Emirates", native: "دولة الإمارات العربية المتحدة", phone: "971", continent: "AS", capital: "Abu Dhabi", currency: "AED", languages: ["ar"] }, AF: { name: "Afghanistan", native: "افغانستان", phone: "93", continent: "AS", capital: "Kabul", currency: "AFN", languages: ["ps", "uz", "tk"] } },
arrayOfNames = Object.values(object).map(({ name }) => name);

console.log(arrayOfNames);

关于javascript - 来自对象和对象的名称数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59896393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com