简体   繁体   English

如何将单行数组转换为多行数组?

[英]How can I convert a single-line array into a multi-line array?

I'm trying to make something that picks a random word out of the english dictionary as a word for the game hangman.我正在尝试从英语词典中随机选取一个词作为游戏刽子手的词。 I found a good word list: http://www.mieliestronk.com/corncob_lowercase.txt and i've managed to convert it into an array.我找到了一个很好的单词列表: http : //www.mieliestronk.com/corncob_lowercase.txt ,我已经设法将它转换成一个数组。 One problem though, it's an array on a single line and it's longer than 20k characters.但是有一个问题,它是一个单行数组,长度超过 20k 个字符。 If i try to copy paste the array into my project, it says that it's too long.如果我尝试将数组复制粘贴到我的项目中,它会说它太长了。 So i wanted to convert it into a multi-line array.所以我想把它转换成一个多行数组。 I've seen people use regexes but everytime i try it, it doesn't work at all... So, does anyone have a solution to my problem?我见过人们使用正则表达式,但每次我尝试它时,它根本不起作用......那么,有人能解决我的问题吗? Note: i've just started programming, so sorry if this question is really stupid or if i didn't explain it correctly.注意:我刚刚开始编程,如果这个问题真的很愚蠢或者我没有正确解释,那么很抱歉。

I would check out prettier https://prettier.io/ , or another code formatter.我会查看更漂亮的https://prettier.io/或其他代码格式化程序。 This will get you started in formatting your code the way you want while you are developing.这将帮助您在开发过程中按照您想要的方式开始格式化代码。

I am unsure what is the question tho我不确定问题是什么

write this into the console将此写入控制台

console.log(document.getElementsByTagName('pre')[0].textContent.split(/\s+/));

you get an array that contains the words as values你会得到一个包含单词作为值的数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM