javascript 使用正则test( )第一次是 true,第二次是false

93 阅读1分钟
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<script>
var data = [{"id":1384,"vr_id":"221","location":"产品1","pro_name":"Single Function Adjustable Flow-rate Shattaf","pro_imgurl":"[{\"name\":\"4.png\",\"url\":\"https:\\/\\/vrres.zhizhan360.com\\/61d4f0d442efa.png\"},{\"name\":\"SS80106-01.jpg\",\"url\":\"https:\\/\\/vrres.zhizhan360.com\\/61d4f0d4bdc9b.jpg\"},{\"name\":\"_DSC0129.JPG\",\"url\":\"https:\\/\\/vrres.zhizhan360.com\\/61d4f13c9571a.JPG\"},{\"name\":\"SS80020-01front.jpg\",\"url\":\"https:\\/\\/vrres.zhizhan360.com\\/61d4f13c92356.jpg\"}]","pro_label":"","pro_vicoe":"https://vrres.zhizhan360.com/61d4f0b68c132.mp4","pro_360url":"","pro_xiangxiurl":"","pro_edi":"<p>·&nbsp;Unique&nbsp;and&nbsp;fashion&nbsp;shape&nbsp;design.</p><p>·&nbsp;Simple&nbsp;and&nbsp;smooth&nbsp;switching&nbsp;flow&nbsp;rate&nbsp;between&nbsp;0&nbsp;and&nbsp;maximum.</p><p>·&nbsp;No&nbsp;need&nbsp;to&nbsp;press&nbsp;all&nbsp;the&nbsp;time&nbsp;to&nbsp;keep&nbsp;open.</p><p>·&nbsp;Convenient&nbsp;to&nbsp;switch&nbsp;on-off&nbsp;with&nbsp;single&nbsp;hand.</p><p>·&nbsp;Panel&nbsp;removable&nbsp;for&nbsp;cleaning.</p><p>·&nbsp;More&nbsp;safer&nbsp;without&nbsp;the&nbsp;pressing&nbsp;handle;</p>","look_num":0,"in_num":0,"like_num":0,"goumai":"","hotspot_name":"cp_01_01","opertype":"1","jump_link":"","pro_type":"产品","pos_number":"A03","logo":"https://vrres.zhizhan360.com/61380bd35490c.jpg","com_name":"Xiamen Unionta Industrial Co., Ltd.","bind_domain":"https://unionta-feb.zhizhan360.com","vrsouce":"https://vr.zhizhan360.com/vrsouce/61cc3b0cb490f/zhanguan9/render/index.html"}];
var reg = new RegExp("Shattaf", "igm");
var result = data.filter((item) => {		
		// reg.lastIndex = 0;
		// item id = 1385
		return (reg.test(item.pro_name) ||
								reg.test(item.pro_label) ||
								reg.test(item.com_name))
});
	console.log(result);
</script>

</body>
</html>

blog.csdn.net/qq_34849000…