STRING METHODS IN JAVASCRIPT PART-2

Опубликовано: 24 Май 2026
на канале: SmituCodes
25
3

JavaScript provides a wide range of string methods to manipulate and interact with strings. Here’s a categorized list of common string methods:

1. String Manipulation
concat(): Combines two or more strings.

javascript
Copy code
let str1 = "Hello";
let str2 = "World";
console.log(str1.concat(" ", str2)); // Output: "Hello World"
toUpperCase(): Converts a string to uppercase.

javascript
Copy code
console.log("hello".toUpperCase()); // Output: "HELLO"
toLowerCase(): Converts a string to lowercase.

javascript
Copy code
console.log("HELLO".toLowerCase()); // Output: "hello"
trim(): Removes whitespace from both ends of a string.

javascript
Copy code
console.log(" Hello World ".trim()); // Output: "Hello World"
replace(): Replaces a substring with another substring.

javascript
Copy code
console.log("Hello World".replace("World", "JavaScript")); // Output: "Hello JavaScript"
replaceAll(): Replaces all occurrences of a substring.

javascript
Copy code
console.log("Hello Hello".replaceAll("Hello", "Hi")); // Output: "Hi Hi"
2. Accessing String Content
charAt(): Returns the character at a specified index.

javascript
Copy code
console.log("JavaScript".charAt(4)); // Output: "S"
charCodeAt(): Returns the Unicode of the character at a specified index.

javascript
Copy code
console.log("A".charCodeAt(0)); // Output: 65
includes(): Checks if a string contains a specified substring.

javascript
Copy code
console.log("JavaScript".includes("Script")); // Output: true
startsWith(): Checks if a string starts with a specified substring.

javascript
Copy code
console.log("JavaScript".startsWith("Java")); // Output: true
endsWith(): Checks if a string ends with a specified substring.

javascript
Copy code
console.log("JavaScript".endsWith("Script")); // Output: true
3. Extracting Parts of Strings
slice(): Extracts a section of a string and returns it as a new string.

javascript
Copy code
console.log("JavaScript".slice(0, 4)); // Output: "Java"
substring(): Similar to slice() but does not accept negative indexes.

javascript
Copy code
console.log("JavaScript".substring(0, 4)); // Output: "Java"
substr(): Extracts a substring based on a start index and length (deprecated).

javascript
Copy code
console.log("JavaScript".substr(0, 4)); // Output: "Java"
4. Splitting and Joining
split(): Splits a string into an array of substrings.

javascript
Copy code
console.log("Hello,World".split(",")); // Output: ["Hello", "World"]
**join()
5. Searching in Strings
indexOf(): Returns the index of the first occurrence of a substring.

javascript
Copy code
console.log("Hello World".indexOf("World")); // Output: 6
lastIndexOf(): Returns the index of the last occurrence of a substring.

javascript
Copy code
console.log("Hello World World".lastIndexOf("World")); // Output: 12
search(): Searches for a match using a regular expression and returns the index.

javascript
Copy code
console.log("Hello World".search("World")); // Output: 6
match(): Returns an array of matches based on a regular expression.



#learnhtml5andcss3#codingchallenge #code #webdevelopment #codewithme #codewithharry#freelance #freecodecamp #sandeepmaheshwari #sandeepmaheshwarimotivational #education #figma #udemyfreecertificate #udemy #frontenddevelopment#codewithharry #education #htmlacademy #htmlcss #css #codehelp #js #upsc #java #codewithharry #frontenddeveloper #javaprogramming#apnacollege #apnacollegestudent #apnacollegestudent #javatutorial#apnacollge #apnacollegestudent #apnacollege #javatutorialsforbeginners#technicalguruji #technicalyogi #technicalanalysis #tutorial #designer #design #engineering #CodingTutorial #CodeWithMe#codehelp #sandeepmaheshwari #sandeepmaheshwarimotivational #ProgrammingTips #DeveloperLife#udemy #figma #TechTips #CodingJourney #CodeChallenge #JavaScript#Python #Java #CSharp#Ruby #PHP #TypeScript #WebDevelopment#WebDevelopment
#LearnWebDev
#CodeWithMe#apnacollege #apnacollegestudent #apnacollge
#FrontendDevelopment
#WebDesign
#JavaScriptTutorial
#HTMLCSS
#CodingForBeginners
#FullStackDev
#WebDevelopmentCourse
#DeveloperTips
#CodingBootcamp #BackendDevelopment#codewithharry #code withharry #FrontendDevelopment #FullStack, #APIs #DatabaseDesign#OOP (Object-Oriented Programming),
#DataStructures #Algorithms#React #NodeJS#Django #Flask#Express, #Angular#VueJS #GraphQL#NextJS #Laravel#SpringBoot #Git#GitHub#Docker #Kubernetes#AWS #Azure#GCP#VSCode #CodingTutorial #CodeWithMe #ProgrammingTips #DeveloperLife #TechTips #CodingJourney #CodeChallenge #viral #viralvideos #youtube #youtubers #codewithharryHashtags: #CSDojo #CodingInterviews #ProgrammingHashtags: #freeCodeCamp #Coding #LearnToCode#codewithharry#codewithherry #shraddhakapra#codingblocks#programminglanguage #codenewbie #coding #earn #freelance #clanguage#codingjourney#WebDevelopment#codewithpython

#FrontendDevelopment

#BackendDevelopment

#FullStackDeveloper

#CodingTutorial

#JavaScript

#LearnToCode

#HTML