i need to select one csv file and convert it in to json list.for that i wrote a javascript function but its not giving the exat json list
this is the js method
- <input type="file" accept=".csv" (change)="convertFile($event)" />
-
- convertFile(csv: any) {
-
- this.fileReaded = csv.target.files[0];
-
- let reader: FileReader = new FileReader();
- reader.readAsText(this.fileReaded);
-
- reader.onload = (e) => {
- let csv: string = reader.result;
- let allTextLines = csv.split(/\r|\n|\r/);
- let headers = allTextLines[0].split(',');
- let lines = [];
-
- for (let i = 0; i < allTextLines.length; i++) {
-
- let data = allTextLines[i].split(',');
- if (data.length === headers.length) {
- let tarr = [];
- for (let j = 0; j < headers.length; j++) {
- tarr.push(data[j]);
- }
-
-
- console.log(tarr);
- lines.push(tarr);
- }
- }
-
- console.log(">>>>>>>>>>>>>>>>>", lines);
- }
but this is giving o/p like
. Array(21)
. 0:(3) ["ONE", "TWO", "THREE"]
. 1:(3) ["9345", "ui: Publishing Start Date and end date should add calendar function", "Committed"]
. 2:(3) ["9339", "gg: The options for default shall be in language table as Y and N", "Approved"]
. 3:(3) ["9295", "URAXR2: A message info is to be added after delete the variable in variable tab ", "bb"]
. 4:(3) ["9276", "bb: Valid error message should be added in Formula tab", "Approved"]
. 5:(3) ["9275", "bb: The spelling of the record is incorrect in…ssage info when deleting record from nntables", "Approved"]
. 6:(3) ["9274", "nn:? The values get blank when edit the record in Group tables tab", "Committed"]
. 7:(3) [
i need to get like below
[
{
color: "red",
value: "#f00"
},
{
color: "green",
value: "#0f0"
},
{
color: "blue",
value: "#00f"
},
{
color: "cyan",
value: "#0ff"
},
]