将单词列表转换成数组 [英] Convert word list into array

查看:109
本文介绍了将单词列表转换成数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图查看是否有任何脚本可以将单词列表转换为数组,但我似乎找不到.

I've tried to see if there were any scripts to convert a list of words into an array and I can't seem to find one.

有人知道我在哪里可以找到吗?

Anyone know where I can find one?

输入:

Dog
Cat
Hamster

转换为

["Dog", "Cat", "Hamster"]

不是.这不是我的意思.我有一个txt文件,每行上都有一堆单词,我想知道是否已经创建了一些东西,可以将每个单词转换为数组.

Noo.. this isn't what I mean. I have a txt file with a bunch of words on each line and I was wondering if there was something out there already created that can convert each word into an array.

推荐答案

只需使用 split .

例如:

var textarea = document.getElementById('list');
var arr = [];
textarea.addEventListener('input', function () {
    arr = this.value.split('\n');
    console.log(arr);
}, false);

演示

这篇关于将单词列表转换成数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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