I have a specific function that converts a two-dimensional array into CSV format. The key requirement is that the function only supports text and numbers, triggering an error message for any other input types. Currently, when I execute the function, it stops working at the first incompatible input encountered. How can I modify the function to handle such situations and continue processing the rest of the array?
function arraysToCsv(data) {
for(let i = 0; i < data.length; i++){
let value = data[i];
for(let j = 0; j < value.length; j++){
if(typeof value[j] !== 'string' || typeof value[j] !== 'number')
throw new Error('Unexpected value');
let result = value[j].replace(/"/g, '""');
if (result.search(/("|,|\n)/g) >= 0){
result = '"' + result + '"';
}
return result.join(',') + '\n';
}
}
}