我想将'this.tag'的值与'this.et'的值匹配。我使用了匹配方法。但是它与" this.tag"的值不符。指导我:匹配两个数组的最佳方法是什么。以下是我的代码。
.ts
this.image_url = [
{ word: 'hi', img: 'user.png' },
{ word: 'hlo', img: 'user.png' },
];
this.TAG= ["hi", "hello hii", "hi", "bye", "aa", "Sd", "Sent now", "hlo", "check tick", "check again", "hi hiii wer", "hi", "HI", "HI", "HI", "HI"];
ngOnInit() {
for(let i=0; i<this.TAG.length; i++) {
setTimeout(() => {
console.log(this.TAG);
console.log(i);
this.et[i]= this.image_url.map(e => e.word);
console.log(this.et[i]);
if(this.TAG[i].match(this.et[i])) {
console.log(this.image_url);
this.show=true;
console.log(this.show);
} else {
console.log("no hii");
}
},100);
}
}
尝试以下代码
this.image_url = [
{ word: 'hi', img: 'user.png' },
{ word: 'hlo', img: 'user.png' },
{ word: 'hloll', img: 'user.png' },
];
this.TAG= ["hi", "hello hii", "hi", "bye", "aa", "Sd", "Sent now", "hlo", "check tick", "check again", "hi hiii wer", "hi", "HI", "HI", "HI", "HI"];
let groups= this.image_url.filter(({word}) => this.TAG.includes(word));
console.log('Output:',groups);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>