Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _parseCSVtoJSONByN(input) {
- const lines = input.split('\n');
- const parsedData = {};
- lines.forEach(line => {
- if (line.trim() === '') return;
- let [key, value] = line.split(': ');
- const match = key.match(/_(\d+)$/);
- if (match) {
- const index = match[1];
- key = key.replace(/_\d+$/, '');
- if (!parsedData[index]) {
- parsedData[index] = {};
- }
- parsedData[index][key] = value;
- }
- });
- return Object.values(parsedData).map(data => { return data; });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement