为 PDFmake 循环遍历两个单独的数组 table

Looping through two separate arrays for PDFmake table

我正在尝试创建一个 pdfmake table,它将数组键作为一列,相应的数组值作为下一列。

下面是我的 firebase 数据库的JSON:

{
  "users" : {
    "useruid" : {
      "wills" : {
        "assets" : {
          "MY IPHONE XR " : [ "my Brother Fab", "my sister Kenny" ],
          "bedside lamps" : [ "my cat Cuddly" ],
          "bottle " : [ "My son Ayo" ]
        },
        "details" : {
          "Daniel thompson" : "19A Silver Road "
        },
        "residual" : [ "my son Paul" ],
        "testators" : [ "my cat cuddly" ]
      }
    }
  }
}

目标是 table 有点像:

PROPERTY      |    BENEFICIARY

MY IPHONE XR  |    MY BROTHER FAB, MY SISTER KENNY
BEDSIDE LAMPS |    MY CAT CUDDLY
BOTTLE        |    MY SON AYO

下面是我试过的代码,但它并没有很整齐地出来:

     admin.database().ref('users').child('useruid').child('wills')
    .child('assets').once('value').then(function(dataSnapshot1) {

        const assets = [];
        const benef = [];

        dataSnapshot1.forEach((childSnapshot) => {
                      const childKey = childSnapshot.key;
                      const childData = childSnapshot.val();
                      assets.push( childKey );  
                      benef.push( childData ); 
                    });
          console.log(assets);
          console.log(benef);

     

var docDefinition = {
    content: [

        
        'I DECLARE that my Executors or any Professional or person engaged in proving my Will and administering the estate may charge reasonable fees for their services ',
        
        '\nI GIVE my property as follows:',
        
        {text: 'Property and Beneficiaries ', style: 'subheader'},
    

        {
            style: 'tableExample',
            table: {
                widths: ['*',100, '*', 200],
                body: [
                    ['No.','Property', 'Beneficiary', 'Beneficiary Address'],
                    [`${assets}`, `${benef}`, {text: '{beneficiary address}'}]
                ]
            }
        },

有没有一种方法可以循环遍历资产数组和受益人数组,也许 foreach 会产生类似

的内容
rows= [];
rows.push([index, asset1, asset 1 beneficiaries])
rows.push([index +1, asset2, asset 2 beneficiaries])

不断?

let rows = [
  ['Property', 'Beneficiary']
];
for (let i = 0; i < assets.length; i +=1) { // i suggest a for-loop since you need both arrays at a time 
  rows.push([assets[i], benef[i]]);
}

table: {
  body: rows,
  headerRows: 1
}