Awo*_*ism 2 javascript node.js
So I'm trying to duplicate the array elements, for example:
var array = ["chicken","nugget","good"];
Run Code Online (Sandbox Code Playgroud)
into:
var array2 = ["chicken","chicken","nugget","nugget","good","good"];
Run Code Online (Sandbox Code Playgroud)
How to done with this?
The idiomatic way would be:
["chicken","nugget","good"].flatMap((x) => [x, x]);
Run Code Online (Sandbox Code Playgroud)
Be aware not all javascript environments have flatMap available yet so transpilation may be required.
| 归档时间: |
|
| 查看次数: |
76 次 |
| 最近记录: |