Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取thrutjy值_Javascript_Foreach - Fatal编程技术网

Javascript 获取thrutjy值

Javascript 获取thrutjy值,javascript,foreach,Javascript,Foreach,我怎样才能得到真实的价值观?我试图比较这些值,但在比较键之前。我想排除具有falsy值的键 function truthCheck(collection, pre) { let a=[] for(let e in collection){ if(console.log(collection[e] && collection[e][pre]==pre )){ return true; }else{

我怎样才能得到真实的价值观?我试图比较这些值,但在比较键之前。我想排除具有falsy值的键

function truthCheck(collection, pre) {
     let a=[]
   for(let e in collection){

   if(console.log(collection[e] && collection[e][pre]==pre )){

                 return true;   
   }else{
           return false;
   }

   }

}




truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastForward", "onBoat": null}], "onBoat");

代码应该类似于:

功能配对(str){
常数s=str.split(“”),a=[];
s、 forEach(v=>{
开关(v.toUpperCase()){
案例“C”:
a、 推动(['C','G']);
打破
案例“G”:
a、 推动(['G','C']);
打破
案例“A”:
a、 推动(['a','T']);
打破
案例“T”:
a、 推送(['T','a']);
打破
}
});
返回a;
}
常数cgc=pairement('GCG'),ttgag=pairement('ttgag');

控制台日志(cgc);控制台日志(ttgag)我不知道如何使用forEach()执行此操作

功能配对(str){
让我们来看看碱基对={
答:“T”,
T:“A”,
C:“G”,
G:“C”
}
设newArr=[];
设entriesBase=str.split(“”);
//对象。条目(entriesBasePairs);

对于(设i=0;对于任何刚刚发布问题解决方案的人:),网站可以免费开放访问多个解决方案,包括官方和用户提交的解决方案。
function pairElement(str) {
  let entriesBasePairs={

    A:"T",

    T:"A",

    C:"G",

    G:"C"

  }
let newArr=[];
let entriesBase =str.split("");
 //Object.entries(entriesBasePairs); 
for(let i=0;i<entriesBase.length;i++)

for (let [key, value] of Object.entries(entriesBasePairs)){

        if(entriesBase[i]==key){

             newArr.push([key, value])    
//console.log(`${key}: ${value}`);

}
}
console.log(newArr)
return newArr;
}
pairElement("GCG");