0

i have variabel data like this, and i want to slice object inside it

[{
    "id_pemasangan_mesin": 0.2879244882244172,
    "wsid": "3Y9W",
    "location_2nd": "Bekasi Timur barat",
    "branch": "0998-SLA. JAKARTA",
    "vendor_pkt_name": "PT NCR INDONESIA",
    "djpw_kcu_induk": "244 - Kalimalang",
    "lokasi_pengambilan_kartu": "0393 - KARTASURA",
    "operational_hour_start": null,
    "city": "Kotamadya Bekasi",
    "djpw_provinsi": "Jawa Barat",
    "djpw_latitude": "-6.248329"
},
{
    "id_pemasangan_mesin": 0.9599194420299093,
    "wsid": "0XPR",
    "location_2nd": "Bekasi Timur barat",
    "branch": "0998-SLA. JAKARTA",
    "vendor_pkt_name": "PT Wakwaw INDONESIA",
    "djpw_kcu_induk": "333",
    "lokasi_pengambilan_kartu": "7735 - THE PARK",
    "operational_hour_start": null,
    "city": "Kotamadya Bekasi",
    "djpw_provinsi": "Jawa Barat",
    "djpw_latitude": "-6.248329"
}]

and i want to make that object like this

[{
    "id_pemasangan_mesin": 0.2879244882244172,
    "wsid": "3Y9W",
    "location_2nd": "Bekasi Timur barat",
    "branch": "0998-SLA. JAKARTA",
    "vendor_pkt_name": "PT Wakwaw INDONESIA",
    "djpw_kcu_induk": "244 - Kalimalang",
    "lokasi_pengambilan_kartu": "0393 - KARTASURA"
},
{
    "id_pemasangan_mesin": 0.9599194420299093,
    "wsid": "0XPR",
    "location_2nd": "Bekasi Timur barat",
    "branch": "0998-SLA. JAKARTA",
    "vendor_pkt_name": "PT NCR INDONESIA",
    "djpw_kcu_induk": "432",
    "lokasi_pengambilan_kartu": "7735 - THE PARK"
}]

what function in javascript to make my respon like my expected anyone can give example? i try splice but the result is work only on array value not object

  • Are you saying you want to remove some *specific* properties? Or is it rather that you want to keep *specific* properties? – trincot Jun 22 '23 at 17:45
  • i just want delete 4 object after "lokasi_pengambilan_kartu", i just want 7 object maximal in each object – Ragil Pratama Jun 22 '23 at 17:47
  • For none mutation you could use `Array.map` for mutation variant just loop and delete the props you don't want. – Keith Jun 22 '23 at 17:47
  • You should not rely on the *order* of properties. If you need *order*, then you should not have those objects in the first place, but work with arrays. – trincot Jun 22 '23 at 17:48
  • let data = arr.map((e) => { let obj = { "id_pemasangan_mesine": e.id_pemasangan_mesin, "wsid": e.wsid, "location_2nd": e.location_2nd, "branch": e.branch, "vendor_pkt_name": e.vendor_pkt_name, "djpw_kcu_induk": e.djpw_kcu_induk, "djpw_kcu_induk": e.djpw_kcu_induk, "lokasi_pengambilan_kartu": e.lokasi_pengambilan_kartu } return obj; }) console.log(data); – Mahadev Mirasdar Jun 22 '23 at 18:02

0 Answers0