JavaScript/格式转换:修订间差异
来自康健生活
创建页面,内容为“== 引言 == == 字符串转数组 == {{Leftrightflex|<syntaxhighlight lang="javascript"> "123456".replace(/(.)(?=[^$])/g, "$1,").split(",");</syntaxhighlight>|{{Con…” |
|||
| 第4行: | 第4行: | ||
"123456".replace(/(.)(?=[^$])/g, "$1,").split(",");</syntaxhighlight>|{{Consoleout|<pre> | "123456".replace(/(.)(?=[^$])/g, "$1,").split(",");</syntaxhighlight>|{{Consoleout|<pre> | ||
(6) ["1", "2", "3", "4", "5", "6"] | (6) ["1", "2", "3", "4", "5", "6"] | ||
</pre>}}}} | |||
== 数组转字符串 == | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
["1", "2", "3", "4", "5", "6"].join('');</syntaxhighlight>|{{Consoleout|<pre> | |||
"123456" | |||
</pre>}}}} | |||
== 数组字符串 == | |||
{{Leftrightflex|<syntaxhighlight lang="javascript"> | |||
JSON.stringify("123456".replace(/(.)(?=[^$])/g, "$1,").split(","));</syntaxhighlight>|{{Consoleout|<pre> | |||
"["1","2","3","4","5","6"]" | |||
</pre>}}}} | </pre>}}}} | ||