If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
JavaScript में String slice() method , दिए गए start - end argument के according String में से sub-string extract करता है। Array की तरह String में letters की indexing 0 से start होती है।
हालाँकि method से Original String में कोई changes नहीं होता है।
string.slice(start : int, end : int);
start | required : यह starting value है , जहाँ से sub-string को select करना है। input value का type integer होना चाहिए।
end | optional : यह end value है , जहाँ तक sub-string को select करना है। इसका type भी integer होना चाहिए।
Return Value : दिए गए input के according , एक selected elements का एक new String return करता है।
File : js_string_slice.html
<!DOCTYPE html>
<html>
<body>
<script>
let str = "Visit learnhinsituts.com to learn PHP , JavaScript , jQuery etc.";
document.write(str.slice(5, 24));
/*select substring from start point*/
document.write("<br>" + str.slice(28));
document.write("<br> original String : "+ str);
</script>
</body>
</html>
learnhinsituts.com learn PHP , JavaScript , jQuery etc. original String : Visit learnhinsituts.com to learn PHP , JavaScript , jQuery etc.
Note : negative value का use करके आप String की end side sub - string select कर सकते हैं।
For Example -
document.write(str.slice(-10));
document.write("<br>" + str.slice(-25, -5));
/*Output*/
Query etc.
JavaScript , jQuery
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook