Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

336
Views
Change border color of a div conditionally angular

I have these two arrays :

Original Array :

$arr_1=['disappear','rising','filled','decades]; 

User Array:

$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
 }

These should return the matching indexes in this case it should return [0,2] indexes because they are matching but in my case it is returning 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'}" 

Any solution to resolve this issue, Thanks

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

  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]
  }
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!