Table of Contents
Introduction
हेलो दोस्तों आज हम इस post में javascript string methods के बारे में जानेगे javascript में string method and properties, string के साथ operation perfom करने में help करते है!. जैसे की string की length find करना string के specific word को chanage करने जैसे operation हम string method के help से कर सकते है!.
Javascript string length
Javascript में length property हमें string की length return करती है!.
Example:
let str = "Hello Rjtechyg"; let newstr = str.length; console.log( newstr );
Javascript slice() method
Javascript में slice() method string को specific position से string को remove कर देता है! और new string लोटता है . slice() method दो parameters pass कर सकते है!. start position और end position
syntax:
slice(start, end);
slice() method दोनों parameter के साथ
let str ="Apple, Banana, Kiwi"; let newstr = str.slice(7, 13); console.log(newstr);
slice() method one parameter के साथ
let str ="Apple, Banana, Kiwi"; let newstr = str.slice(5); console.log(newstr);
toUpperCase() javascript method
Javascript में string को uppercase में convert करने के लिए toUpperCase() method का इस्तेमाल किया जाता है!.
Example:
let str = "apple, banana, kiwi"; let upperstr = str.toUpperCase() console.log(upperstr);
toLowerCase() javascript method
Javascript में string को lowercase में convert करने के लिए toLowerCase() method का इस्तेमाल किया जाता है!.
Example:
let str = "APPLE, BANANA, KIWI"; let lowerstr = str.toLowerCase() console.log( lowerstr );
javascript replace() method
replace() method एक case sensitive method है इस लिए string में जिस word को replace करना चाहते है exact word replace() method में pass करना होता है!. मान लीजिये अगर string में आपको “Hello” word को replace “Hi” word के साथ करना है तो आप कुछ इस तरह method में pass करा सकते है!.
Example:
let str ="Hello world"; let newstr = str.replace("Hello", "Hi"); console.log( newstr );
javascript concat() method
Javascript में एक या एक से अधिक string को joins करने के लिए concat() method का इस्तेमाल किया जाता है!.
Example:
let str = "Hello"; let str1 = "This is new world"; let newstr = str.concat("",str1); console.log( newstr );
javascript trim() method
Javascript में trim() method string के दोनों side (left or right) से whitespace को remove करने के लिए इस्तेमाल kiya जाता है!.
Example:
let str = " Hello world "; let newstr = str.trim(); console.log( newstr );
Pingback: Javascript string in hindi