Var stdin = process.openStdin();
stdin.addListener("data",function(d){});
How can I fetch input from this? I've tried d.toString.trim();
But later when I push in the array it is also pushing \n
in the array.
Var stdin = process.openStdin();
stdin.addListener("data",function(d){});
How can I fetch input from this? I've tried d.toString.trim();
But later when I push in the array it is also pushing \n
in the array.
You can try this
var stdin = process.openStdin();
let arr=[];
stdin.addListener("data",function(d){
arr.push(d.toString().replace(/\r?\n|\r/g, " "));
console.log(arr);
});
See repl
Reference answer-for string replace