簡體   English   中英

我可以在 JS 中傳播空數組嗎?

[英]Can I spead empty array in JS?

我在運行以下代碼時收到此錯誤Uncaught SyntaxError: expected expression, got '...'

[1,2,3, (true ? 4 : ...[])]

是否可以像這樣傳播一個空數組?

您需要傳播表達式,但不能將數組傳播為單個表達式。

 const array = [1, 2, 3, ...(true ? [4] : [])]; console.log(array);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM