I'm developing a game which needs a wordlist called "words.txt" and inside this file, it looks like :
zoologie
zozoter
Zurich
zygote
And i need to convert it to an Array for VueJS which will look like :
export default {
data(){
return{
words: ["zoologie", "zozoter", "Zurich", "Zygote"]
}
}
}
The problem is that i don't know how to do it, because if i proceed 1by1, it will take a long time (22k words in it)
Thank you.
If you have node installed, you can do something like this:
let fs = require("fs");
let string = `export default {
data(){
return{
words: [`;
fs.readFileSync("words.txt").toString().split("\n").forEach(el => {
string += `"${el}",`;
});
string += `]
}
}
}`;
fs.writeFile("yourfile.js", string);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.