<script>
let lines=[];
let Array;
fetch("questions.txt").then(response =>{
console.log(response.status);
response.text().then(response =>{
console.log(response);
Array=lines.split("\n");
})
});
</script>
我正在尝试读取我的txt文件的行,但是我不能
发布于 2021-12-03 02:00:42
lines
已经是一个数组。数组不能拆分,因为它们已包含多个元素。
这可能就是你想要做的:
let lines;
fetch("questions.txt").then(response =>{
console.log(response.status);
response.text().then(response =>{
console.log(response);
lines=response.split(/\r?\n/);
})
});
来源(用于拆行):https://github.com/30-seconds/30-seconds-of-code/blob/master/snippets/splitLines.md
https://stackoverflow.com/questions/70212378
复制