Remapped 2d array

by chrisloughnane

JavaScript

let source = [
	[{
			"_id": "5efbb97e80752985301c3447",
			"row": 1,
			"position": 0,
			"tab": 1
		},
		{
			"_id": "5efbb97e80752985301c3453",
			"row": 1,
			"position": 1,
			"tab": 1
		}

	],
	[{
			"_id": "5efbb97e80752985301c3411",
			"row": 2,
			"position": 0,
			"tab": 1
		},
		{
			"_id": "5efbb97e80752985301c3414",
			"row": 2,
			"position": 1,
			"tab": 1
		},
		{
			"_id": "5efbb97e80752985301c33f3",
			"row": 2,
			"position": 2,
			"tab": 1
		}
	],
	[{
		"_id": "5efbb97e80752985301c343b",
		"row": 3,
		"position": 0,
		"tab": 1
	}],
	[{
			"_id": "5efd026180752985301c8641",
			"row": 4,
			"position": 0,
			"tab": 1,
			"faIconPrefix": "fas",
			"faIconNg": "external-link-alt"
		},
		{
			"_id": "5efd026180752985301c8644",
			"row": 4,
			"position": 1,
			"tab": 1,
			"faIconPrefix": "fas",
			"faIconNg": "external-link-alt"
		}
	],
	[{
			"_id": "5efd026180752985301c861d",
			"row": 5,
			"position": 0,
			"tab": 1,
			"faIconPrefix": "fas",
			"faIconNg": ""
		},
		{
			"_id": "5efd026180752985301c8620",
			"row": 5,
			"position": 1,
			"tab": 1,
			"faIconPrefix": "fas",
			"faIconNg": ""
		}
	]
]

let updatePackage = {};
updatePackage.tab = 1;
let dataset = [];
dataset = source.map((subarray) => subarray.map((row) => row._id));
updatePackage.dataset = dataset.map((row, rowIndex = 0) => {
          rowIndex++;
          return {
            row: rowIndex,
            ids: row,
            iconDefault: '5e7824c67bd78eb199e95f3e',
          };
        });
document.body.append(JSON.stringify(updatePackage));