简体   繁体   English

从数组对象中提取感兴趣的数据

[英]extract data of interest from array object

i am trying to extract specific data from an array object using keys but all the data gets returned? 我试图使用键从数组对象中提取特定数据,但所有数据都被返回了? why is that? 这是为什么? i want to print to the console all the values corresponding to the key genestart only 我只想将与键genestart对应的所有值打印到控制台

for (var i=0; i<genedata.matches.length;i++){                                                                                                         
        var arr = genedata.matches[i];                                                                                                                    
        for (var key in arr){                                                                                                                             
            var attrName=key;                                                                                                                             
            var attrValue = arr[key];                                                                                                                     
            //console.log(attrValue);                                                                                                                     
            if (attrName='genestart'){                                                                                                                    
              console.log(attrValue);                                                                                                                     

            }                                                                                                                                             
        }                                                                                                                                                 
    }     

Your if statement is not a comparison but an assignment. 您的if语句不是比较而是分配。 Change = to == 将=更改为==

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM