javascript - Node.js Seperate each line into an array of integers -
i'm trying access text file , have array , have each line array of numbers.
it returns on node.js
9235 9096 637
and want return
[[9235], [[9096],[637]]
index.js
console.log("hello world"); var fs = require('fs'); var array = fs.readfilesync('txt/numbers.txt').tostring().split("\n"); for(i in array) { console.log(array[i]); }
numbers.txt
9235 9096 637
if other answers aren't correct , wanted array of arrays each line:
array.map(function(line) { return line.match(/\d+/g).map(function (n) { return [+n]; }); });
Comments
Post a Comment