const JSONtoCSV = (arr: Array<object>, columns: string[], delimiter = ',') =>
        [
          columns.join(delimiter),
          ...arr.map(obj =>
            columns.reduce(
              (acc, key) =>
                `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
              ''
            )
          ),
        ].join('\n');
      
      Typescript language logo

      Convert JSON to CSV

      0

      0

      avatar
      Giovanny Gongora
      Codiga's TypeScript Recipes

      Converts an array of objects to a comma-separated values (CSV) string that contains only the columns specified.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.