本文介绍了将对象值提取到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将所有名称从下面的对象中拉出并存储到数组中. 我需要这个的原因是能够使用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"].
更多推荐
将对象值提取到数组中
发布评论