এক্সট্রা স্পেস রিমুভ করতে trim() এবং রেগুলার এক্সপ্রেশন ব্যবহার করুন। Trim()-এর আগে স্ট্রিং:
var sentence = "My name is John Smith ";
স্পেস রিমুভ করার কোড:
উদাহরণ
var sentence = "My name is John Smith "; console.log("The actual value="); console.log(sentence); var originalSentence = sentence.replace(/\s+/g, '').trim(); var afterRemovingTheSpace = originalSentence.trim(); console.log("After removing the spaces="); console.log(afterRemovingTheSpace); রান কমান্ড: node fileName.js। ফাইল নাম demo90.js।
আউটপুট
PS C:\Users\Amit\JavaScript-code> node demo90.js The actual value= My name is John Smith After removing the spaces= MynameisJohnSmith