js
str.trim()بتشيل كل whitespace: مسافة، tab، سطر جديد وغيرها، من الطرفين بس، مش من النص نفسه. فيه trimStart وtrimEnd للطرف الواحد.
امتى أستخدمها
قبل ما تقارن أو تخزّن input من مستخدم. نص ' admin' مش بيساوي 'admin'.
البرهان
js
const s = ' \t hi there \n ';
console.log(JSON.stringify(s.trim()));
console.log(JSON.stringify(s.trimStart()));
console.log(JSON.stringify(s.trimEnd()));
console.log('a b'.trim());النتيجة
"hi there" "hi there \n " " \t hi there" a b