Javascript - Apply trim function to each string in an array

后端 未结 11 1353
-上瘾入骨i
-上瘾入骨i 2020-12-07 14:22

Want to trim each string in an array, e.g., given

x = [\' aa \', \' bb \'];

output

[\'aa\', \'bb\']

My fi

11条回答
  •  难免孤独
    2020-12-07 14:54

    Influencing from Bergi's perfect answer, i just would like to add, for those methods which won't take a this argument, you may achieve the same job as follows;

    var x = [' aa ', ' bb '],
        y = x.map(Function.prototype.call.bind(String.prototype.trim))
    

提交回复
热议问题