Pretty sure this has been discussed thousands of times but haven't found a perfect replacement for my code snippet below.
Since the use of for...of construct is not allowed, how can I write following code?
// lines is an array of strings
let value = ''
for (const line of lines) {
try {
const json = JSON.parse(line)
if (json) {
value = json.whatever
/*
more logic irrelevant to this question
*/
// As soon as first jsonable line is found and processed, short-circuit the loop
break
}
} catch (err) {
// Handle error
// throw / reject / console.error() / return - could be anything
}
}
Pretty sure this has been discussed thousands of times but haven't found a perfect replacement for my code snippet below.
Since the use of
for...ofconstruct is not allowed, how can I write following code?