我想要数组索引中的文件内容,请在下面找到示例
I want contents of file in array index , please find example below
// 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|登录 ID:pvgA1248|密码:Root@123
所以,我想要的是直到日期它应该是第 0 个索引,直到 loginID 1st 等等..
请帮我实现同样的目标..
我不确定我的理解是否正确,但您想拆分数组中每行的所有值?
像这样:
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);
// 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|登录 ID:pvgA1248|密码:Root@123 所以,我想要的是直到日期它应该是第 0 个索引,直到 loginID 1st 等等.. 请帮我实现同样的目标..
我不确定我的理解是否正确,但您想拆分数组中每行的所有值?
像这样:
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);