如何在 NodeJS 中使用与 python 中的 splitlines() 类似的东西 [英] How do I use a similar thing to splitlines() from python in NodeJS

查看:15
本文介绍了如何在 NodeJS 中使用与 python 中的 splitlines() 类似的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 username:password 列表,我想将它们分开,我该怎么做:

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;

这样我就可以拥有一个包含 10 多个用户名/密码的大列表,我的脚本可以自动从 txt 文件中提取这些用户名/密码,然后登录到每个单独的帐户.

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.

推荐答案

您正在寻找 String#split() 这将接受一个字符串并根据给定的参数将其拆分为子字符串数组.

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'

这篇关于如何在 NodeJS 中使用与 python 中的 splitlines() 类似的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆