[英]Extract Object Values into an Array
I am needing to pull all of the names out of the object below and store into an array. 我需要将所有名称从下面的对象中拉出并存储到数组中。 the reason I am needing this is to be able to use the JQuery tag-it plugin for auto complete.
我需要这个的原因是能够使用JQuery tag-it插件来自动完成。 So if you know of a better way I can do this other than creating a new array I am all ears.
因此,如果您知道一个更好的方法,除了创建一个新数组之外,我可以做到的一切,我无所不能。
{
"user": [
{
"title": "boss",
"name": "scott"
},
{
"title": "janitory",
"name": "bob"
},
{
"title": "dictation",
"name": "betty"
},
{
"title": "vp",
"name": "ted"
}
]
}
Expected Output = ["scott","bob","betty","ted"] 预期输出= [“ scott”,“ bob”,“ betty”,“ ted”]
var arr = [{name:'Abe'},{name:'Bart'},{name:'Cletus'},{name:'Duffman'}];
var names = arr.map(function(a) { return a.name; });
names contains ["Abe", "Bart", "Cletus", "Duffman"]
. 名称包含
["Abe", "Bart", "Cletus", "Duffman"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.