举例如:
var operationList = []; var editObj = {‘name‘:‘edit‘}; operationList.push(editObj); // 判断是否含有edit和add console.log( operationList.map(item => item.name).indexOf(‘edit‘) ); // 输出0 console.log( operationList.map(item => item.name).indexOf(‘add‘) ); // 输出-1
作为if条件时只需将结果与0作比较;
原文:https://www.cnblogs.com/xuyinshan/p/14714126.html