将对象值提取到数组中

编程入门 行业动态 更新时间:2024-10-24 16:30:15
本文介绍了将对象值提取到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将所有名称从下面的对象中拉出并存储到数组中. 我需要这个的原因是能够使用JQuery tag-it插件来自动完成. 因此,如果您知道除了创建一个新数组之外,我还能做的更好的方法,那么我将不知所措.

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. 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" } ] }

预期输出= ["scott","bob","betty","ted"]

Expected Output = ["scott","bob","betty","ted"]

推荐答案

var arr = [{name:'Abe'},{name:'Bart'},{name:'Cletus'},{name:'Duffman'}]; var names = arr.map(function(a) { return a.name; });

名称包含["Abe", "Bart", "Cletus", "Duffman"].

更多推荐

将对象值提取到数组中

本文发布于:2023-10-27 03:30:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组中   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!