Ramin Rabii Ramin Rabii - 1 year ago 59
Javascript Question

Javascript normal Array value and Array value created by match function comparison

I have issue with two type of arrays value comparison, here is

tagNames = [];

cmt_wrds = '‏‏61'.replace(/[`~!@#$%^&*()_|+\-=?;:'",،؛«».<>\{\}\[\]\\\/]/gi, ' ').match(/\S+/g);

if ( tagNames[0] == cmt_wrds[0] ) { // issue is here
console.log('yes'); // --> nothing

Answer Source

If you log your variables you will see that they are a bit different. It puts


symbol which is the Right-To-Left Mark.

var tagNames = [];

 cmt_wrds = '‏‏61'.replace(/[`~!@#$%^&*()_|+\-=?;\u200f:'",،؛«».<>\{\}\[\]\\\/]/gi, ' ').match(/\S+/g);


console.log(tagNames[0] === cmt_wrds[0]); // returns false, because they are different

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download