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'].map(String.prototype.trim);
...but my console said...
TypeError: String.prototype.trim called on null or undefined
jsFiddle.
I can't see any null
or undefined
values in my array.
String.prototype.trim()
and Array.prototype.map()
are defined in Chrome 17, which I'm using to test.
Why doesn't this work? I get the feeling I have overlooked something obvious.
I realise I could loop or drop a function in there. That's not the point of this question, however.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…