js 在数组对象中匹配到指定的数据

options: [{
          value: '1',
          label: '黄金糕'
        }, {
          value: '2',
          label: '双皮奶'
        }, {
          value: '3',
          label: '煎蛋'
        }, {
          value: '4',
          label: '龙须面'
        }, {
          value: '5',
          label: '北京烤鸭'
        }],

需求: 匹配到value = 3的这条数据

let res = options.find(item => {return item.value === '3'})
//{value: '3',label:'煎蛋'}

 

posted @ 2024-09-09 11:58  龙卷风吹毁停车场  阅读(194)  评论(0)    收藏  举报