I am parsing a csv file in javascript using the logic below. The logic works correctly in the Firefox browser, but in the Chrome browser, the result is different.
var r = new FileReader();
r.onload = function (e) {
contents = e.target.result;
$scope.$apply(function () {
$scope.fileReader = contents;
contents = contents.replace(/\r\n+/g, ",");
reqObj.names = contents.split(",");
defer.resolve("Succesfully executed");
});
};
r.readAsText(file);
Output in Firefox: names: ["pradeep", "naveen", "kiran"] Output in Chrome: names: ["pradeep \ nnaveen \ nkiran"]
Please let me know where I am going wrong.
source
share