Run details:
Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Mobile Safari/537.36
Chrome Mobile 103
Android
Mobile
2 years ago
Test name Executions per second
regex 817655.0 Ops/sec
trim 3960676.5 Ops/sec
Script Preparation code:
AخA
 
var string = '    fsajdf asdfjosa fjoiawejf oawjfoei jaosdjfsdjfo sfjos 2324234 sdf safjao j o        sdlfks dflks l      '
Tests:
  • regex

     
    string.replace(/^\s+|\s+$|\s+(?=\s)/g, '')
  • trim

     
    string.trim()