我对两种类型的数组值比较有疑问,这里是
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
};
最佳答案
如果您记录变量,您会发现它们有些不同。它把
'\u200f'
符号是 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
关于Javascript普通数组值和匹配函数比较创建的数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40212027/