lundi 7 septembre 2015

Checking if condition with javascript variables

I have a string array like this

function checkAlreadyShortlisted()
            {
                var shortListed = new Array();                    
                shortListed = '["Mr. Andrew Severinsen", "Mr. Tom Herron", "Ms. Samantha Smithson-Biggs", "Mr. Efrem Bonfiglioli", "Mr. Giles Forster"]';
                var candidateName = '';
                $('.searchResultCandidateDiv').each(function(i, obj) {

                    candidateName = $(this).find('.viewResumeAnchor').text();  // Get the text from the particular div
                    console.log(candidateName);
                    if(candidateName == shortListed[4])   // Copied the value from Set
                    {
                        console.log('Got from Set');
                    }              
                    else if(shortListed[4] == "Mr. Giles Forster") // Copied the value from anchor
                    {
                        console.log('Got from Anchron text');
                    }
                });
            }

In the div looped I have to check if the name in the shortlisted array is present or not.

These are values I copied from browser console log

Mr. Efrem Bonfiglioli Mr. Giles Forster

Checking condition with above text is working fine, but if I try to check the values with array string it is not working properly. But text are similar any ideas?

Aucun commentaire:

Enregistrer un commentaire