Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个变量中的行列表,如下所示:
var crDelimited = "Hello \n Bye \n extract me \n I stay"
不知何故,我想从 crDelimited 中提取第三行
有什么想法吗?
以下将为您提供第三行,或者undefined如果少于三行:
undefined
crDelimited.split("\n")[2]
或者,如果您也想对其他行执行某些操作,则保留对由返回的行数组的引用.split():
.split()
var lines = crDelimited.split("\n"); // lines[2] would be the third line