JavaScript Tutorial

String, Number, Math, Array

JavaScript tutorial

This is a method. It is used to find out a char from at the specified index in a string, and return a char value. The index number is always starts from 0.

syntax: charAt() syntax is :- string.charAt(index). Here index is position of character.

Example:

var sentence=’’i am writing at medium”;

console.log(“The char at index 0 is”+sentence.charAt(0));

result is: The char at index 0 is i

2.concat()

concat() method combines two, three or more strings. It returns a new strings. But it doesn’t change original string. If the type of arguments are not string , they are converted to string.

syntax: concat(str1,str2,…..,strn)

Example:

let sen = ‘It is ‘
console.log(sen.concat(‘amazing.’))

Result is: ‘It is amazing.’

3.toLowerCase()

The toLowerCase() method is used to convert the string value to lowercase, And return string in lowercase letter.

Syntax: string.toLowerCase()

Example: let str=”HIMANSGSU”
console.log(str.toLowerCase());

Result is: ‘himansgsu’

4.toUpperCase()

The toUpperCase() method is used to convert the string value to lowercase, And return string in lowercase letter.

Syntax: string.toUpperCase()

Example: let str=”Bangladesh is beautiful country”
console.log(str.toUpperCase());

Result is: ‘’BANGLADESH IS BEAUTIFUL COUNTRY’’

5.slice()

The slice()method divided a part of string, and it returns divided part to new string. This method takes two parameter start index and end index

Syntax: string.slice(start index,end index)

Example: let str = ‘what day is today.’
console.log(str.slice(4))
console.log(str.slice(4, 8))

Result is: ‘ day is today.’
‘ day’

6.replace()

This method replace a part of value in a string, and return a new string.

Syntanx: string.replace(searchstr,replacestr)

Example: let str = ‘Today is friday.’;
let newstr = str.replace(‘friday’, ‘sunday’);
console.log(newstr);

Result is: ‘Today is sunday.’

7.indexOf()

The indexOf()method is used to search a specified value in string, and returns a first position within a string. It is case-sensitive method.

Syntax: indexOf(searchValue)

Example: const str = ‘beauty of nature’
console.log(“first position is :”+str.indexOf(‘of’)

Result is: ’first position is :7

8.lastIndexOf()

The lastIndexOf()method is used to search a specified value in string, and returns a last position within a string. It is case-sensitive method.

Syntax: lastIndexOf(searchValue)

Example: const str = ‘nature of beauty’
console.log(“last position is :”+str.lastIndexOf(‘e’))

Result is: ‘last position is :11

9.parseInt()

This method parses a string argument and convert to integer. It returns integer value.

Syntax: Number.parseInt(stringValue)

Example: let stringValue=”50.34"
Number.parseInt(stringValue);

Result is :50

10.parseFloat()

parseFloat method parses a sting argument and covert it to floating point number. It returns floating point number from given sting value.

Syntax: Number.parseFloat(stringValue)

Example: let stringValue=”50.34Value”
Number.parseFloat(stringValue);

Result is :50.34

Hi, This is Himangsu Sarkar. I am a web developer . I would love to learn new things related technology.