判断一个对象数组中某一项是否某一个值?

 1 const data = [{
 2    name: "撤回",
 3    type: "withdraw"
 4 }, {
 5    name: "...",
 6    type: "other",
 7    children: [{
 8       name: "会签",
 9       type: "sign"
10    }]
11 }];
12 
13 const exist = data.some(item => item.type.indexOf('sign') > -1);

打印结果:

true

posted @ 2020-11-05 17:22  程序員劝退师  阅读(842)  评论(0编辑  收藏  举报