DEV Community

front_end_shifu_2022
front_end_shifu_2022

Posted on

String obj:

string Objects

in js strings are objects.
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
Use the following syntax to create a String object :
let value = new String(string);

string property

length Returns the length of the string.
e.g.
let human = " john pepper";
human.length;
let length = human.lenght;
console.log(human.length);

String Methods

CharAt():

return the character at specified index.
let human = " john pepper";
console.log(human.charAt(1)) // o

indexOf():

Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.
let human = " john pepper";
console.log(human.indexOf(e)); // 6

toLowerCase():

Returns the calling string value converted to lower case.
*let human = " John Pepper";
console.log(human.toLowerCase()); //john pepper

toUpperCase():

Returns the calling string value converted to upperCase.
let human = " John Pepper";
console.log(human.toUpperCase()); //JOHN PEPPER

slice()

Extracts a section of a string and returns a new string.
let human = " John Pepper";
console.log(human.slice(1,4)); //OHN

This is all for now I'll share more in my upcoming posts.

Top comments (0)