Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created September 13, 2021 05:30
Show Gist options
  • Save Risyandi/dfe3fcf566c0f8f32c04c4656f5000ab to your computer and use it in GitHub Desktop.
Save Risyandi/dfe3fcf566c0f8f32c04c4656f5000ab to your computer and use it in GitHub Desktop.
convert array object, to array multidimension
let dataProps = [{
"id": 1,
"mat_doc": "5000001724",
"mat_doc_year": 2020,
"mat_doc_item": 1,
"ref_doc_num": "SJ1234567892",
"header_text": null,
"posting_date": "2020-08-09T17:00:00.000Z",
"doc_date": "2020-08-09T17:00:00.000Z",
"move_type": "101",
"mat_num": null,
"short_text": "OEM S110 CSD",
"mat_desc": "OEM S110 CSD",
"plant_id": "S110",
"storage_loc": null,
"batch_num": null,
"vendor_code": "0000600099",
"vendor_name": null,
"qty_po": null,
"base_uom": null,
"qty_gr": "500",
"unit_entry": "DUS",
"po_id": "4510111936",
"po_item": "1",
"company_code": "NSI",
"reason_move": "1101",
"item_text": null,
"good_receipt": null,
"qty_sj": 500,
"uom": "DUS",
"exp_date": null,
"order_num": "301500000005"
},
{
"id": 1,
"mat_doc": "5000001724",
"mat_doc_year": 2020,
"mat_doc_item": 1,
"ref_doc_num": "SJ1234567892",
"header_text": null,
"posting_date": "2020-08-09T17:00:00.000Z",
"doc_date": "2020-08-09T17:00:00.000Z",
"move_type": "101",
"mat_num": null,
"short_text": "OEM S110 CSD",
"mat_desc": "OEM S110 CSD",
"plant_id": "S110",
"storage_loc": null,
"batch_num": null,
"vendor_code": "0000600099",
"vendor_name": null,
"qty_po": null,
"base_uom": null,
"qty_gr": "500",
"unit_entry": "DUS",
"po_id": "4510111936",
"po_item": "1",
"company_code": "NSI",
"reason_move": "1101",
"item_text": null,
"good_receipt": null,
"qty_sj": 500,
"uom": "DUS",
"exp_date": null,
"order_num": "301500000005"
}]
// data from table selected
let dataContent = [];
let dataColoumn = [];
Object.entries(dataProps).forEach(([key, value]) => {
let valueKey = Object.keys(value);
let valuesObj = Object.values(value);
dataContent.push(valuesObj);
dataColoumn.push(valueKey);
})
console.log(dataContent, 'dataContent');
console.log(dataColoumn, 'dataColoumn');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment