我有這個陣列的陣列
a1 = ['one', 'two', ['three', 'four'] ] 。
如何從子陣列中獲取'three'和'four',并將其作為字串推入父陣列,如下所示
a2 = ['one'/span>, 'two'/span>, 'three, four'/span>]。
像這樣。 我可以用for回圈來做,但它很冗長,我可以用ES6來解決這個問題嗎?
注意:在'三'和'四'之間有空格,如a2所示。
uj5u.com熱心網友回復:
。const a1 = ['one'/span>, '二', ['三', '四'] ]。
const a2 = a1.map(v => Array. isArray(v) ? v.join(', ') : v) 。
console.log(a2);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/322404.html
標籤:
