node.js - 我想要数组索引中的文件内容,请在下面找到示例
问题描述
// fs.readFile(file, [encoding], [callback]);
// converting file and storing it in an array
var fileRefer = fs.readFileSync('LoginID\\Creds.txt').toString().split("\n");
for (f in fileRefer) {
let i = fileRefer[f];
const [, , , , id, , pw,] = i.split(" "); //pipe sep. |
// console.log(id,pw);
let username = id;
let password = pw;
示例-日期:2021-11-08 17:01:33|LoginID:pvgA1248|密码:Root@123 所以,我想要的是直到日期它应该是第 0 个索引,直到 loginID 第 1 个等等。请帮我达到同样的..
解决方案
我不确定我是否正确,但您想将数组中每行的所有值拆分?
像这样:
let str = "Date: 2021-11-08 17:01:33|LoginID: pvgA1248|Password: Root@123";
let result = str.split('|').reduce((a,v) => {
v.split(': ').forEach(s=>a.push(s));
return a;
},[]);
console.log(result);
推荐阅读
- blazor - 是否有任何已知的公开计划让 Microsoft 的 Office Fabric UI 在 Blazor 中得到支持?
- python-3.x - 如何将具有相同值的两行合并为python中的单行?
- java - RestTemplate mapping Page '页面大小不得小于一'
- apache-nifi - 在 Nifi 的自定义处理器中评估单个字段中的表达式和正则表达式
- c++ - 在 R 和 C++ 中编写一个始终返回值“1”的函数
- java - 有没有办法使用 ESC 命令获取热敏打印机的状态?
- javascript - 如何使用jQuery选择树中的最后一个孩子?
- javascript - Hiding DataTable div
- r - Filling the gap in the time series
- google-analytics - How to implement the Google Analytics event monitoring on a website if the standard Analytics tracking code seems not to be enough?