Javascript普通数组值与match函数创建的数组值比较
Javascript normal Array value and Array value created by match function comparison
我有两种类型的数组值比较的问题,这里是
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'
符号,即从右到左标记。
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
使用一些变量来给出一个输入数据,它将解决您的问题。
(function () {
tagNames = [];
tagNames.push('61');
var datas ="61";//variable declaration
cmt_wrds = datas.replace(/[`~!@#$%^&*()_|+'-=?;:'",،؛«».<>'{'}'[']'''/]/gi, ' ').match(/'S+/g);
if ( tagNames[0] == cmt_wrds[0]) { // issue is here
console.log('yes'); // --> nothing
};
})()
如果您显示它们的长度,则差异如下。
tagNames[0].length
= 2
cmt_wrds[0].length
= 4
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
};
console.log(tagNames[0].length);
console.log(cmt_wrds[0].length);
相关文章:
- 从多维嵌套json数组创建下拉列表
- 为对象数组创建列表项
- 如何在cycle js中从JSON数组创建组件
- 使用数据数组创建多个类似组件
- 如何在 Angular JS 中从关联数组创建多个复选框
- 如何为给定数组创建跨度列表
- 如何在javascript中使用2个一维数组创建层次结构树
- 从数据对象数组创建折线图
- 从 javascript 数组创建一个 Jquery 数组
- Angular2从数组创建一个列表
- 使用JavaScript's Reduce从对象数组创建数组
- 如何从数组创建 jqtree
- 从字符串数组创建唯一组合数组
- 反应.js通过数组创建循环
- 从数组创建新元素,直到每秒数组为空
- 如何使用其他流的值数组创建流
- JavaScript:从字节数组创建图像资源
- 使用拆分字符串的数组创建一个对象
- 从一组数据或数组创建对象
- 多维数组 - 创建一个表