簡體   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