Ramin Rabii Ramin Rabii - 11 months ago 37
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