I'm slurping up fields from an API that returns an array of fields. Each field in the array is a String that actually contains two separate fields (a number and a date). The number is enclosed in parentheses and the date is following this and a space. The following is an example of the format.
const data = [
"(2) 2020-09-15", "(3) 2020-09-16"
];
I'm parsing this field and then storing the data separately in my app. I have my own numbers and dates fields that will be a String in which each number and date is separated by a newline.
I'm achieving this by doing the following.
let numbers = '', dates = numbers;
for (let datum of data) {
datum = datum.split(/[() ]/);
numbers += `${datum[1]}\n`;
dates += `${datum[3]}\n`;
}
See an example here.
I don't particularly like this and am wondering if there's a more efficient and cleaner way to write this.