繁体   English   中英

如何从 object 中提取值并将其放入数组中

[英]how to extract valuefrom object and put it into array

我想提取 filterPillvalue 并将其放入一个数组中,数组的 output 应该是这样的:

mode = ['anyValue','Repsonding','Unresponsive']

这是我的尝试

this.items = [
  {
    filterPillValue: 'anyValue',
    id: 'all-systems',
    label: 'All systems'
  },
  {
    filterPillValue: 'Responding',
    id: 'responding',
    label: 'Responding systems'
  },
  {
    filterPillValue: 'Unresponsive',
    id: 'unresponsive',
    label: 'Unresponsive systems'
  }
];

我的尝试在这种情况下不起作用

mode = this.items.filter(x=>x.filterPillValue);

这会起作用。

mode = this.items.map(({filterPillValue}) => filterPillValue);

要么

mode = this.items.map((item) => item.filterPillValue);

 items = [ { filterPillValue: 'anyValue', id: 'all-systems', label: 'All systems' }, { filterPillValue: 'Responding', id: 'responding', label: 'Responding systems' }, { filterPillValue: 'Unresponsive', id: 'unresponsive', label: 'Unresponsive systems' } ]; const node=items.map(item=>item.filterPillValue) console.log(node)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM