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

201
Views
Object from echo PHP (Laravel) is not iterable in javascript

I'm trying to iterate an object that is comming from a PHP file via jquery ajax, but even when is a simple array I get an error.

        let addresses = connection ('post',{search: term},'/orders-addresses').then((data)=>{
            // this gets :['address 1', 'addres 2']
            console.log(data);
            return( data );
        });
        
        // This gets: Uncaught TypeError: addresses.map is not a function
        addresses.map((address)=>{
            console.log(address);
        });

        // This gets: Uncaught TypeError: Uncaught TypeError: addresses is not iterable
        for(address of addresses){
            console.log(address);
        }

The PHP (Laravel) code is:

    $addresses = Order::orderBy('address','asc')->select('id','address')->limit(5)->groupBy('address');
    $response = [];

    if($request->search != ''){
        $addresses = $addresses->where('address', 'like', '%' .$request->search . '%');
    }
    
    $addresses = $addresses->get();

    foreach($addresses as $address){
        $response[] = $address->address;
     }

    echo json_encode($response);
about 4 years ago · Juan Pablo Isaza
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!