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

后端 未结 4 1947
南笙
南笙 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:44

    trim is on the String prototype, meaning that it expects the this context to be that of a string where as the map method on Array provides the current array item as the first argument and the this context being the global object.

提交回复
热议问题