0

queryResultArr is the array that olds mysql queries results, let say i have in my table two columns: doc_1_hits and doc_2_hits, but i don't know prior how much docs i have and i want to run a loop like you can see below: queryResultsArr[0].doc_i_hits instead of doc_1_hits.

i tried a: var str = 'doc_'+i+'_hits'; and then queryResultsArr[0].str but nothing..

for(var i = 1; i < 3; i++){
    if(queryResultsArr[0].doc_i_hits > 0 && queryResultsArr[1].doc_i_hits == 0){
        console.log(i);
    }
}

1 Answer 1

2

I think you could use the array notation and do it like below because they work similar in this case.

var a = 'doc_'+i+'_hits';
queryResultsArr[0][a] 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.