【问题标题】:How to change an array of .. arrays and subarrays (and subsubarray) to a simple array in regex (trough javascript?)如何将 .. 数组和子数组(和子子数组)的数组更改为正则表达式中的简单数组(通过 javascript?)
【发布时间】:2022-01-08 07:11:46
【问题描述】:

我有以下问题。我有一个多维数组,我想将其转换为一维数组,因此可以将它们作为数组循环。我将整个代码粘贴到了 pastebin (https://pastebin.com/kitjY8CG)。

我希望尝试使用正则表达式来做到这一点。但是,我对如何解决这个问题的想法有限。最简单的方法是让正则表达式选择括号之间的所有内容并最终将其更改为数组。 这可能吗?

[
[["https://www.website.be/set.aspx?Id=4589232","https://www.website.be/set.aspx?Id=4737287","https://www.website.be/set.aspx?Id=5054137","https://www.website.be/set.aspx?Id=4776617" [..] ],["https://www.website.be/set.aspx?Id=4899728" [..] ,"https://www.website.be/set.aspx?Id=2650424" "https://www.website.be/set.aspx?Id=3807271"]],[["https://www.website.be/set.aspx?Id=2834602 .. "https://www.website.be/set.aspx?Id=3807271"]],[[ .....

感谢您的帮助。

【问题讨论】:

  • 为什么用正则表达式而不是简单的 array.flat() ?
  • 您好,我不知道“array.flat()”存在 :-)
  • 你现在知道了 :) 我将不胜感激。
  • 我想...但我需要 15 个声望点才能投票:
  • 那就别担心了!

标签: javascript regex select


【解决方案1】:

如果您的数组是实际数组而不是字符串。

yourArray.flat(); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 2017-11-29
    • 2011-01-24
    • 1970-01-01
    • 2016-10-07
    • 2012-08-18
    相关资源
    最近更新 更多