I have a list of username:password
and I'm wanting to separate each of them, how would I be able to do like:
let username = usernameValue;
let password = passwordValue;
So that I can have a big list of say 10 username/password that my script can automatically pull from the txt file to then login into each individual account.
CodePudding user response:
You're looking for String#split()
this will take a string and split it into an array of sub-strings based off the given argument.
const value = 'username:password';
const [usernameValue, passwordValue] = value.split(':');
console.log(usernameValue);
// 'username'
console.log(passwordValue);
// 'password'
CodePudding user response:
Probably you have split lines first
var lines = text.match(/^.*((\r\n|\n|\r)|$)/gm);
and then
lines.map((i) => i.split(":"))