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

115
Views
How to filter multiple array in object then display
const data = {
      test1: [
        {error: ''},
        {error: ''},
      ],
      test2: [
        {error: ''},
        {error: 'theres an error in this field'},
        {error: 'theres an error here'},
      ],
      test3: [
        {error: ''},
        {error: 'theres an error'},
        {error: 'theres an error here'},
      ]
    };

how to filter data with an error value and display on it?

  const test1 = data.test1.filter(x => x.error !== ''); 
        const test2 = data.test2.filter(x => x.error !== ''); 
        const test3 = data.test3.filter(x => x.error !== ''); 
        
            <div>
               <div *ngFor="let test of test1">
                    {{test.error}}
               </div>
               <div *ngFor="let test of test2">
                    {{test.error}}
               </div>
               <div *ngFor="let test of test3">
                    {{test.error}}
               </div>
            </div>

I'm not sure it this is the correct way.

What I'm trying to do is display all the errors by listed without a space just like this

theres an error in this field
theres an error here
theres an error
theres an error here
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since you are using Angular, and therefore Typescript, you should type your variables. .some() returns a boolean, not an array, so const test1 should be const test1:boolean. And now you see you can't do *ngFor="let test of test1" on a boolean.

Replace .some with .filter, which does return an Array, and you should be good.

const test1: {error:string}[] = data.test1.filter(x => x.error !== '');
about 4 years ago · Juan Pablo Isaza Report

0

You can extract all errors from data using:

interface ErrorResponse {
  error?: string;
}
const errors: ErrorResponse[] = Object.values(data).flat().filter(row => row.error);

and then display them using:

<div *ngFor="let response of errors">
   {{response.error}}
</div>

Refs: .filter(), .flat().

about 4 years ago · Juan Pablo Isaza 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!