简体   繁体   中英

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

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. Change = to ==

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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