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

87
Views
Iterate array objects in js

I have an array objects it looks like

\[
{id: 1, name: 'first', properties: \[{id: 1, name: 'propName1'}, {id: 2, name: 'propName2'}\]},
{id: 2, name: 'second', properties: \[{id: 1, name: 'propName1'}, {id: 2, name: 'propName2'}\]},
{id: 3, name: 'third', properties: \[{id: 1, name: 'propName1'}, {id: 2, name: 'propName2'}\]},
\]

I want to display first name of object for example 'first' and then I want to display names of properties objects propName1, propName2 so I want to see

first

propName1 propName2

second

propName1 propName2

third

propName1 propName2

Could you help me, guys?

I tried

{filters.map((filter) => {
  let propss = ArrayFrom(filter.properties);
  propss.map((prop) => (
    <div>{prop.displayName}</div>
  ))

  return(
    <div className={style.title}>{filter.displayName}</div>
  )

  filter.properties.map((prop) => {
    return (
      <>
        <div className={style.title}>{filter.displayName}</div>
        <div>{prop.displayName}</div>
      </>
    );
  });
})}

and I tried to save array via reduce, but without any result

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First of all, you should not name yout array 'filter' since this can be confused with the Array.prototype.filter method ;)

Then you have an array of objects containing arrays, so you should iterate at the two level (in case your real structure actually gots more depth, you probably need to take a recursive approach).

considering your entry point :

const data = [
  {
    id: 1,
    name: 'first',
    properties: [
      {id: 1, name: 'propName1'},
      {id: 2, name: 'propName2'}
    ]
  }, {
    id: 2,
    name: 'second',
    properties: [
      {id: 1, name: 'propName1'},
      {id: 2, name: 'propName2'}
    ]
  }, {
    id: 3,
    name: 'third',
    properties: [
      {id: 1, name: 'propName1'},
      {id: 2, name: 'propName2'}
    ]
  },
]

the two iterations couls look like somthing like that :

return data.map(entry => (
  <>
    <div className={style.title}>{entry.name}</div>
    {entry.properties.map(prop => (
      <div>{prop.name}</div>
    ))}
  <>
))
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!