Tengo estas dos matrices:
Matriz original:
$arr_1=['disappear','rising','filled','decades];Matriz de usuario:
$arr_2=['disappear','filled','filled','decade]; this.indexesAttention=[]; $arr_1.forEach(x=>{ //concat two arrays this.indexesAttention=[...this.indexesAttention, ...this.checkValue(x)] }); checkValue(variable:string):number[] { return this.arr_2 .map((x,index)=>x.trim()==variable.trim()?index:-1) .filter(x=>x!=-1) //only want the index>>-1 } Estos deberían devolver los índices coincidentes, en este caso deberían devolver índices [0,2] porque coinciden, pero en mi caso está devolviendo 0,2,1,3
[ngStyle]="(indexesAttention.indexOf(i)<0) ? {'border-color':'red','color':'red'} : show_answer === false ? {'border-color': 'black','color':'black'} : {'border-color': 'green','color':'green'}"Alguna solución para resolver este problema, gracias
arr1 = ['disappear','rising','filled','decades']; arr2 = ['disappear','filled','filled','decade']; constructor(){ const a = this.arr2.map((e,k) => { const i = this.arr1.indexOf(e); return k == i?i:-1; }).filter(e => e != -1) const rs = [...new Set(a)]; //output [0, 2] }