js的各种循环遍历

  1. for循环遍历查找:
var arr = [{name:'al'},{name:'ba'},{name:'age'}];
var target = 'age';
for(var i=0; i<arr.length; i++){
  if(arr[i].name === target){
    console.log('找到了!');
    break;
  }
}


3.getIntDictOptions('system_user_sex').forEach((oj)=>{return(oj.value == scope.row.sex)})
//啥也没返回  啥也不是
  1. filter方法过滤查找:

var arr = [{name:'a'},{name:'b'},{name:'o'}];
var target = 'o';
var result = arr.filter(function(item){
  return item.name === target;
});
console.log(result);
//[{name:'o'}]
  1. find方法查找:
var arr = [{name:'a'},{name:'b'},{name:'g'}];
var target = 'g';
var result = arr.find(function(item){
  return item.name === target;
});
console.log(result);
//{name:'g'}
  1. some方法查找:
var arr = [{name:'le'},{name:'na'},{name:'an'}];
var target = 'an';
var result = arr.some(function(item){
  return item.name === target;
});
console.log(result);
//true
  1. map方法遍历查找:
var arr = [{name:'ae'},{name:'baa'},{name:'n'}];
var target = 'n';
arr.map(function(item){
  if(item.name === target){
    console.log('找到了!');
  }
})

//[false,false,true]

你可能感兴趣的:(javascript,前端,开发语言)