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

119
Views
use foreach in this array in javascript

the output is like this (its sort of date)

{"2022-04":[{"id":3,"price":"822.000","receipt":"Uploads\\Advertise\\2022\\05\\05\\apple-watch.png","visit":"23","sourse_id":2,"published_at":"2022-04-06T02:22:07.000000Z","deleted_at":null,"created_at":"2022-05-05T00:20:33.000000Z","updated_at":"2022-05-05T02:22:20.000000Z"}],"2022-05":[{"id":2,"price":"500.000","receipt":"Uploads\\Advertise\\2022\\05\\05\\Affidavit of Support I20 Request Form 2021-2022 Rates.pdf","visit":"47","sourse_id":2,"published_at":"2022-05-05T02:13:17.000000Z","deleted_at":null,"created_at":"2022-06-15T00:18:15.000000Z","updated_at":"2022-05-05T00:38:11.000000Z"}]}

now i want to foreach to this array

in php i use like this now in js what should i do?

   foreach ($ads as $key => $ad) {
        $day = $key;
        $totalCount = $ad->sum('visit');
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use Object.entries() to make the object into an array and then iterate through it using any looping function you like.

const data = {"2022-04":[{"id":3,"price":"822.000","receipt":"Uploads\\Advertise\\2022\\05\\05\\apple-watch.png","visit":"23","sourse_id":2,"published_at":"2022-04-06T02:22:07.000000Z","deleted_at":null,"created_at":"2022-05-05T00:20:33.000000Z","updated_at":"2022-05-05T02:22:20.000000Z"}],"2022-05":[{"id":2,"price":"500.000","receipt":"Uploads\\Advertise\\2022\\05\\05\\Affidavit of Support I20 Request Form 2021-2022 Rates.pdf","visit":"47","sourse_id":2,"published_at":"2022-05-05T02:13:17.000000Z","deleted_at":null,"created_at":"2022-06-15T00:18:15.000000Z","updated_at":"2022-05-05T00:38:11.000000Z"}]}
Object.entries(data).forEach(d => {
  // Insert your code for each iteration here
   console.log(d);
});

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!