Ramin Rabii Ramin Rabii - 1 month ago 6
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 = [];

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


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

Answer

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

'\u200f' 

symbol which is the Right-To-Left Mark.

var tagNames = [];

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

console.log(tagNames);
console.log(cmt_wrds);

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

Comments