Open this example in the interactive library
Source code
import { Readable } from "node:stream";
import { createInterface } from "node:readline";
const input = Readable.from([
'{"title":"Tide","tags":["sea","blue"]}\n',
'{"title":"Dune","tags":["sand","gold"]}\n',
'{"title":"Reef","tags":["sea","gold"]}\n',
'{"title":"Blank","tags":[]}\n',
]);
const rows = [];
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
rows.push(JSON.parse(line));
}
const result = rows.map((r) => ({
...r,
tags: r.tags.filter((tag) => tag !== "blue"),
}));
console.log(JSON.stringify(result, null, 2));
Sample output
[
{
"title": "Tide",
"tags": [
"sea"
]
},
{
"title": "Dune",
"tags": [
"sand",
"gold"
]
},
{
"title": "Reef",
"tags": [
"sea",
"gold"
]
},
{
"title": "Blank",
"tags": []
}
]