Why won't passing `''.trim()` straight to `[].map()`'s callback work?

后端 未结 4 1948
南笙
南笙 2020-12-05 18:04

I have an array of strings. I want to trim each string in the array.

I thought using [].map() with \'\'.trim() would work...

[\' a\', \' b   \', \'c         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 18:38

    With ES6 syntax it can be as easy as this:

    [' hello  ', '  world'].map(str => str.trim());
    

提交回复
热议问题