JavaScript strings are used for storing and manipulating text.It is an object that represents sequence of characters.
Eg:
var name= "Bob";
var name= 'Bob';
String length
Below is the code for find the length of a string
var name = "John Smith";
var val = name.length;
JavaScript String Methods
Let's see the list of JavaScript string methods with examples.- charAt(index)
- concat(str)
- indexOf(str)
- lastIndexOf(str)
- toLowerCase()
- toUpperCase()
- slice(beginIndex, endIndex)
- trim()
charAt ()
var str="hellowworld";
document.write(str.charAt(4));
document.write(str.charAt(4));
output: o
concat(str)
var str1="hello";
var str2="world";
var str3=str1.concat(str2);
document.write(str3);
var str2="world";
var str3=str1.concat(str2);
document.write(str3);
output: hello world
indexOf(str)
var str1="helloworld from javascript";
var num=str1.indexOf("from");
document.write(num);
var num=str1.indexOf("from");
document.write(num);
output: 11
lastIndexOf(str)
var str1="hellowworld from javascript";
var num=str1.lastIndexOf("java");
document.write(num);
var num=str1.lastIndexOf("java");
document.write(num);
output: 16
toLowerCase()
var str1="JavaScript toLowerCase Example";
var str2=str1.toLowerCase();
document.write(str2);
var str2=str1.toLowerCase();
document.write(str2);
Output: javascript tolowercase example
toUpperCase()
var str1="JavaScript toUpperCase Example";
var str2=str1.toUpperCase();
document.write(str2);
var str2=str1.toUpperCase();
document.write(str2);
Output: JAVASCRIPT TOUPPERCASE EXAMPLE
slice()
var str1="abcdefgh";
var str2=str1.slice(2,5);
document.write(str2);
var str2=str1.slice(2,5);
document.write(str2);
output: cde
trim()
var str1=" javascript trim example ";
var str2=str1.trim();
document.write(str2);
var str2=str1.trim();
document.write(str2);
output: javascript trim example
Great post!! This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Basically Wonderful. I am also a specialist in this topic so I can understand your hard work.
ReplyDeleteDigital marketing company in Chennai
the blog is very interesting and will be much useful for us. thank you for sharing the blog with us. please keep on updating.
ReplyDeleteInformatica Training in Chennai Adyar
This blog is having the general information. Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog. This is very interesting and useful.
ReplyDeleteiOS App Development Company
ReplyDeletePretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
Android App Development Company
These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
ReplyDeleteiOS App Development Company
These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
ReplyDeleteFitness SMS
Fitness Text
Salon SMS
Salon Text
Investor Relation SMS
Investor Relation Text