I scrape a webpage that it has a table. I returned the array like this:
[
[
'Veículo',
'Entrega\nSem/Com oco\nQtde',
'Entrega\nSem/Com oco\nKg',
'Com oco Kg\n%'
],
[
'AAA3B43',
'0 / 29',
'0 / 1.712',
'100\n100\n100\n '
],
[
'BBB8922',
'0 / 22',
'0 / 1.170',
'100\n100\n100\n '
]
];
My array is bigger than this and it have a lot of columns, with empty fields. I posted just the necessary.
Then, I would like to return the same data but replacing \n by | to save in a text file and proccess this after that.
I tried the code below but this not working.
var oldArray = [
[
'Veículo',
'Entrega\nSem/Com oco\nQtde',
'Entrega\nSem/Com oco\nKg',
'Com oco Kg\n%'
],
[
'AAA3B43',
'0 / 29',
'0 / 1.712',
'100\n100\n100\n '
],
[
'BBB8922',
'0 / 22',
'0 / 1.170',
'100\n100\n100\n '
]
];
var newArray = new Array;
oldArray.forEach((lines, index) => {
lines.forEach((childLines, childIndex) => {
newArray.push(lines.map(function(item){
return item.replace(/\r?\n|\r/g,'|');
}));
});
});
console.log(newArray);
May anyone help me?