Trouble using jquery-csv library

740 Views Asked by At

As I am using React in ES6 and am using Jquery-CSV library, I was unable to import using

var $ = jQuery = require('jquery');
require('./jquery.csv.js');

Found a way to import using

import * as randomName from 'jquery-csv'

Now how am I able to use

$.csv.toArrays(csv);```/```$.csv.toObjects(csv);?

I tried to play around by using names as prefix like randomName.csv.toArrays() but no luck.

EDIT:


randomName.toArray(csv); this works,

but now I am getting the following error

TypeError: csv.replace is not a function

How to solve this?

2

There are 2 best solutions below

0
Dhaval Jardosh On BEST ANSWER

Able to access the library and while passing string as input, I am able to get the them in Array.

input="This is a Random string"

randomName.csv.toArray(input)

Output: ["This is a Random string"]

0
user9973630 On

Same result here using React

import $ from 'jquery'
var csv  = $.csv = require('jquery-csv');
var input="This is a Random string"
tableau_d = csv.toArray(input)
alert(tableau_d)

Output : "This is a Random string"