how to work with double quotation marks

2

I have the following string of a CSV file

var arreglo = ['"Marcopolo b1 "', '"Marcopolo b1, Leito "','"Marcopolo b2, "']

var headers = allTextLines[0].split(/\t|,/);

// this function returns:

var allTextLines = ['"Marcopolo b1 "', '"Marcopolo b1, Leito "','"Marcopolo b2, "']
 for (var i = 1; i < allTextLines.length; i++) {
var cut = allTextLines[i].split(/\t|,/);
console.log(cut);

}

but what I hope is output:

{ "Marcopolo b1 " }, { "Marcopolo b1, Leito " }, { "Marcopolo b2, " }

How would the pattern be to result in this? Thanks

Sorry for not having explained well, what happens is that I have a * .csv file to validate, which has the following values: name, description, mail "TRANS COPACABANA", "description of the mission, description1, description 2", "[email protected]" If you look at the description column I have double quotes and two commas, and I need to recover that entire description, removing only double quotes and not being considered as another column by the commas that it presents, more or less like this: description of the mission, description1, description 2

    
asked by Filomon Fernandez 31.07.2018 в 12:38
source

1 answer

6

As you present it:

var allTextLines = [
    '"Marcopolo b1 "', 
    '"Marcopolo b1, Leito "',
    '"Marcopolo b2, "'
];

This is not a chain but an arrangement, and you do not need to use split to separate it

var allTextLines = ['"Marcopolo b1 "', '"Marcopolo b1, Leito "', '"Marcopolo b2, "']
for (var i = 0; i < allTextLines.length; i++) {
  var cut = allTextLines[i];
  console.log(cut);
}

However, you also said that you wanted the exit in the form:

{ "Marcopolo b1 " }, { "Marcopolo b1, Leito " }, { "Marcopolo b2, " }

And that part I definitely do not understand. Do you want to log into the console the entire array instead of doing it element by element? Or do you want to concatenate the elements using curly braces? The following snippet does both to see if any of them serve you:

var allTextLines = ['"Marcopolo b1 "', '"Marcopolo b1, Leito "','"Marcopolo b2, "']
console.log.apply(console,allTextLines);

console.log('{${allTextLines.join('},{')}}')
    
answered by 31.07.2018 в 12:57