简体   繁体   English

将对象值提取到数组中

[英]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.

相关问题 动态将数组值提取到对象中 - Extract Array values into object dynamically 提取 object 数组中的动态 object 值 - Extract dynamic object values in object array 在给定数组的情况下提取对象值的功能方法 - Functional way to extract object values given an array 将具有多个属性的对象数组分组并根据特定值提取值 - group an array of object with multiple properties and extract values based on the particular values 如何将对象的属性值提取到数组中并使数组中的元素不同? - How to extract the property values of a object into an array and make elements in the array different? 如何一一提取作为关联数组(对象)值的数组元素 - How to extract array elements that are values ​of an associative array (object) one by one 通过javascript中的字符串数组从对象中提取键和值 - Extract keys and values from object via an array of strings in javascript 如何使用 Lodash 4 在 JSON 数组对象中提取值? - How to extract values inside a JSON array object using Lodash 4? Javascript - 一行提取从对象到数组的值 - Javascript - One-liner to extract values from object to array 如何遍历并从复杂对象(数组)中提取属性值? - How to loop through and extract property values from a complex object (Array)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM