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

140
Views
filter array into different array on the basis of fields

I have a array as follows:

[
  {
            "values": [
              {
                "title": "Status",
                "text": "closed"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "overdue"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "open"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "open"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2021-12-24"
              }
            ]
    },
      {
            "values": [
              {
                "title": "Status",
                "text": "closed"
              },
              {
                "title": "Timeline",
                "text": "2021-12-06 - 2022-01-29"
              }
            ]
    }
]

I want my final output in three arrays closedArray,openArray,dueArray. I want to traverse this array, go to status field, check status. if status is closed, then put element in closedArray, if overdue then put element in due array, if open put element in open array. If date in Timeline field passed the current date, then need to put that element in openArray. How can I do this?

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

0

Hey please check this out:

const results = {};
const array=[{values:[{title:"Status",text:"closed"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"overdue"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"open"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"open"},{title:"Timeline",text:"2021-12-06 - 2021-12-24"}]},{values:[{title:"Status",text:"closed"},{title:"Timeline",text:"2021-12-06 - 2022-01-29"}]}];


array.forEach(e => (
   new Date(e.values[1].text.split(" - ")[1]) > new Date() ? // check if date has passed
      results["open"]?.push(e) || (results["open"] = [e]) : // if yes -> add to open array
   results[e.values[0].text]?.push(e) || (results[e.values[0].text] = [e]) // else add to other key
));

const {open, closed, overdue} = results;
console.log("openArray", open);
console.log("closedArray", closed);
console.log("overdueArray", overdue);

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!