javascript 数据查找

原文链接:https://blog.csdn.net/weixin_45022563/article/details/119675272

1.数组是数字或者字符串类型的

  var a = ["1","2"];
  alert(a.indexOf("3"));//返回-1

2.数组是json对象

  var a = [{name:"1"},{name:"2"}];
  alert(a.findIndex(suibiandebianliangmingcheng=>{return suibiandebianliangmingcheng.name=="1"}));//返回0
  alert(a.findIndex(suibiandebianliangmingcheng=>{return suibiandebianliangmingcheng.name=="3"}));//返回-1

 

posted @ 2022-06-16 16:53  单纯的桃子  阅读(212)  评论(0编辑  收藏  举报