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
JSON Object into Comma Separated String

I have problem with converting JSON Object into string with comma separated,

Here's my code:

    $.ajax({
        url:'<?= site_url('chartstatus') ?>',
        method:'get',
        success:function(response){
            var nama_status = [];
            let jumlah=null;
            $.each(response.chartstatus,function(key, value){
              status = value['abs_status'].toString();
              nama_status = '"'+status+'"'+", ";
              jum = value['total'];
              jumlah = jum+", ";
              
            });
            console.log(nama_status);
            console.log(jumlah);
        } 
        });
    }

But the result is always only put first value into variable,

Here's my ajax response:

{
 chartstatus: [
 {
  abs_status: "Bekerja",
  total: "12"
  },
  {
  abs_status: "Tanpa Keterangan",
  total: "5"
  },
  {
  abs_status: "Hari Libur",
  total: "1"
 }
 ]
}

I want result like this :

12, 5, 1,

and

"Bekerja", "Tanpa Keterangan", "Hari Libur",
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Push each value into an array and then use .join() to make a comma-delimited string.

const response = {
  chartstatus: [{
      abs_status: "Bekerja",
      total: "12"
    },
    {
      abs_status: "Tanpa Keterangan",
      total: "5"
    },
    {
      abs_status: "Hari Libur",
      total: "1"
    }
  ]
}

let nama_status = [];
let jumlah = [];

$.each(response.chartstatus, function(key, value) {
  status = value.abs_status.toString();
  nama_status.push('"' + status + '"');
  jumlah.push(value.total)

});
console.log(nama_status.join(', ')); 
console.log(jumlah.join(', '));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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!