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

157
Views
Array iteration inside array of objects

I need to write a function that will go through all array objects and check wether at least one object has inner array where all objects have boolean value set to true. Please see code examples for better understanding.

Example 1

const array = [
  {
    id: 1,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 2,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 3,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: true }, 
    ],
  },
];

functionToBeCreated(array); // Output: true - because item with id 3 has innerArray where all items have "clicked: true".

Example 2

const array = [
  {
    id: 1,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 2,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 3,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: true }, 
    ],
  },
];

functionToBeCreated(array); // Output: false - because no item has innerArray where all items have "clicked: true".

Do you have maybe any ideas how it ca be achieved?

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

0

this way...

const ToBeCreated = arr =>
   arr.some( el => el.innerArray.every(z => z.clicked));

const arrayTRUE = 
  [ { id: 1, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: false }
      ] } 
  , { id: 2, innerArray: 
      [ { innerId: 1, clicked: true  } 
      , { innerId: 2, clicked: false } 
    ] } 
  , { id: 3, innerArray: 
      [ { innerId: 1, clicked: true } 
      , { innerId: 2, clicked: true } 
  ] } ] 

const arrayFALSE = 
  [ { id: 1, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: false }
      ] } 
  , { id: 2, innerArray: 
      [ { innerId: 1, clicked: true  } 
      , { innerId: 2, clicked: false } 
    ] } 
  , { id: 3, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: true  } 
  ] } ] 

// test 
console.log( ToBeCreated(arrayTRUE ) ) 
console.log( ToBeCreated(arrayFALSE) ) 

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!