2017-12-15 15 views
-1

'this.TAG'の値と 'this.et'の値を一致させたいと思います。私はmatchメソッドを使用しました。 'this.TAG'の値と一致しません。 ガイド: 2つの配列を照合する最良の方法は何ですか?以下 がイオン2の2つの配列の値をどのように一致させるか?

.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); 
    } 
} 
+1

以下の試みは、あなたが "二つの配列が一致" によって何を意味するかdescibeすることはできますか?また、あなたのコードprettiesをフォーマットしてください、thsは非常に読みにくいです。さらに、この質問はAngularまたはIonicとは関係ありません。あなたはアルゴリズムについて尋ねているようです。 –

+0

あなたの配列はどこですか? 'this.et' –

+0

this.et [i] = this.image_url.map(e => e.word); console.log(this.et [i]); これは 'this.et'です。私は一致させたい –

答えて

0

..私のコードであるコード

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>

関連する問題