简体   繁体   中英

Is there a shorter way to join an array to one string besides Array.prototype.join()?

I want to join an array to one string. Normally I would write:

x=a=>a.join('')

x([1,2,3,4,5]);         // '12345'
x(['a','b','c','d']);   // 'abcd'
x(['1','2']);           // '12'
x([undefined,null]);    // ''

Is there any way to write this function using even less characters?

借助ES6的模板文字,您可以这样编写:

x=a=>a.join``

如果您愿意使用default ,分隔符:

x=a=>a+''

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM