javascript 中的数组,我如何学习操作它?

发布于 2024-08-29 09:20:16 字数 309 浏览 4 评论 0原文

我读过很多关于 javascript 中数组的核心实现的内容,我经常发现实验是最好的学习方式,

现在我有多种形式,您可以在其中输入不同的内容, 我希望能够提取每个值并将其放入一个数组中,以便稍后可以在动态创建的 div 中读取它们。

有人能指出我正确的方向吗?

有一种方法可以解决这个问题,那就是只使用一种形式,并从那里拉出用逗号 (,) 分隔的文本。问题是我不知道如何从表单中提取文本,搜索并找到逗号,然后创建一个我认为必要的新变量,然后将其读入。我知道如何“思考”javascript,而不是怎么写呢。

我如何以最简单/最快的方式学习?

I've read a lot about the core implementation of arrays in javascript and often I find that experimenting is the best way to learn,

Right now i have multiple forms where you can type in different things,
i want to be able to pull the value of each one and put it in an array so that i can later on read them in in a dynamically created div.

Can anyone point me in the right direction?

There is a way I could get around this and that would be by using just one form, and pulling the text from there separated by comas (,). the thing is that i don't have the knowledge to pull the text form the form, search and find the comas, then make a new variable i think is necessary, and read that in. I know how to "think" javascript, not how to write it.

how do I learn the easiest/fastest way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2024-09-05 09:20:16

如果我理解更正您的问题,您可以使用 split 函数从字符串中获取数组, 此处 Mozilla 有关它的文档。
您还可以使用逗号以外的其他字符并使用正则表达式来处理它们:)

希望它有帮助

,例如:

let text="Dog,Cat,Duck,Mouse";
let myArray=text.split(',');

If I understand correction your question, you can use the split function to get your array from your string, here the documentation of Mozilla about it.
You can also have other character than coma and use RegEx for deal with them :)

Hope it helps

example:

let text="Dog,Cat,Duck,Mouse";
let myArray=text.split(',');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文