为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

肥皂起泡泡 2023-03-18 17:39:37
我想提取 filterPillvalue 并将其放入一个数组中,数组的输出应该是这样的: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);
查看完整描述

2 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

这会起作用。

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

或者

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


查看完整回答
反对 回复 2023-03-18
?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

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)


查看完整回答
反对 回复 2023-03-18
  • 2 回答
  • 0 关注
  • 83 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信