编程语言
首页 > 编程语言> > javascript 数据查找

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

 

标签:findIndex,return,name,javascript,suibiandebianliangmingcheng,alert,查找,var,数据
来源: https://www.cnblogs.com/luna-hehe/p/16382609.html