10 Methods Of JavaScript

So let’s get started.

……………………………………….

1. How to Split a String into an Array in JS

Example :

let story = “I will tell the story”;

console.log(story.split(“ ”));

Output : [“I”, “will”, “tell” “the” “story”];

2. String.toLowerCase() Method

Example :

let story = “I WILL TELL THE STORY”;

console.log(story.toLowerCase(“ ”));

Output : [“i will tell the story”];

3. String.toUpperCase() Method

Example :

let story = “i will tell the story”;

console.log(story.toUpperCase(“ ”));

Output : [“I WILL TELL THE STORY”];

4. string.replace() Method

Example :

const pet= ‘I love cats’;

console.log(pet.replace(‘cats’, ‘birds’));

Output : [“I love birds”];

5. String.trim() Method

Example :

const pet= “ I love cats ” ;

console.log(pet.trim(“”));

Output : [“I love cats”];

6. String.trimStart() Method

Example :

const greeting= “ hello!” ;

console.log(greeting.trimStart(“”));

Output : [“hello”];

7. String.trimEnd() Method

Example :

const greeting = “ hi! ” ;

console.log(greeting.trimEnd(“”));

Output : [“hi”];

8. math.floor() Method

Example :

let number = 5.567

let result = math.floor(number)

console.log(result);

Output : 5 ;

9. array.push() Method

Example :

const animals = [ “cat”, “snake”];

const count = animals.push(“dog”);
console.log(animals);

Output : [“cat”, “snake”, “dog”];

10. array.pop() Method

Example :

const animals = [ “cat”, “snake”];

const count = animals.pop(“ ”);
console.log(animals);

Output : [“cat”];