0

I have string of an array like the following:

  let temparr = ['01.10.2019    1570950138      Accounts Receivable     21000  ',
                       '                        Retailer Opening                        21000 '];


I would like to convert this array like the following json file

const convertedObjectdata = {
            'Date': 01.10.2019,
            'VoucherNo': 1570950138,
            'chartOfAccount: [Accounts Receivable,Retailer Opening]
            'CreditAmount': [21000],
            'DebitAmount': [21000]
        }
Aunog
  • 47
  • 1
  • 9

2 Answers2

1

Split by a sequence of two or more spaces using a regular expression:

const str = 'Date           Voucher No.     Chart of Accounts       Debit Tk.      Credit Tk.'

const result = str.split(/\s{2,}/)

console.log(result)
Ori Drori
  • 183,571
  • 29
  • 224
  • 209
0

You can split on a space regex

str.split(/\s+/);
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406