X कैरेक्टर्स के बाद स्ट्रिंग काटने के लिए, जावास्क्रिप्ट से substr() फ़ंक्शन का उपयोग करें। निम्नलिखित जावास्क्रिप्ट कोड है जिसमें हम 9वें कैरेक्टर के बाद स्ट्रिंग काट रहे हैं -
उदाहरण
var myName="JohnSmithMITUS";
console.log("The String="+myName)
var afterXCharacter = myName.substr(0, 9) + "\u0026";
console.log("After cutting the characters the string="+afterXCharacter);ऊपर, यूनिकोड "\u0026" सभी कैरेक्टर्स को &("\u0026") से बदल देगा।
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा -
node fileName.js.
यहां, मेरा फ़ाइल नाम demo34.js है।
आउटपुट
यह निम्नलिखित आउटपुट देगा।
PS C:\Users\Amit\JavaScript-code> node demo34.js The String=JohnSmithMITUS After cutting the characters the string=JohnSmith&