1. includes()
The includes() method search in a string for one string. If the string found it return true, otherwise return false. The method is case-sensitive.
syntex: includes(searchString)
Example: const string = ‘Hello, Iam learning javascript’;
const search = ‘javascript’;
console.log(`The word “${search} ${string.includes(search)? ‘is’ : ‘is not’} in the sentence`);
output: “The word “javascript” is in the sentence”
2. string slice()
The slice() method picks out a part of a string and returns the picked parts in a new string. The first character position would be 0, and then the second position would be 1, and so on.
syntex: str.slice(beginIndex, endIndex)
Example: const str = ‘Hello, Iam learning javascript’;
console.log(str.slice(0, 4))
output: “Hello”
3. string indexOf()
The indexOf() method returns the position of a specified value in a string. It is case-sensitive. The method returns -1 if the specified value is not found.
syntex: str.indexOf(searchValue)
Example: const str = ‘Hello, Iam learning javascript’;
const searchItem = ‘learning’;
const position = str.indexOf(searchItem);
console.log(`The index of the item “${searchTerm}” is ${position}`);
output: The index of the item “learning” is 11
4. string trim()
The trim() method removes whitespace from both ends of a string.
Syntex: str.trim()
Example: const str = ‘ Hello, Iam learning javascript ‘;
console.log(str.trim());
output: ‘Hello, Iam learning javascript’
5. Math.random()
Math.random() returns number from 0 to 1.
syntex: Math.random()
Example: Math.random()
output: 0.234444, 0.97354 ….
6. isNaN()
This function determines whether a value is a number or not
syntex: isNaN()
Example: const check = ‘hello’;
console.log(isNaN(check))
const check = 12;
console.log(isNaN(check))
output: true (for hello), false (for 12)
7. sqrt()
The sqrt() method returns the squre root of a number.
syntex: Math.sqrt()
Example: const num = 9;
console.log(Math.sqrt(num));
output: 3
8. reduce()
Reduce is an array method that convert an array into a single value. It doesn’t work for an empty array.
Example: const arr = [3, 5, 7];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
console.log(arr.reduce(reducer));
output: 15
9. unshift()
This method adds one or more elements in the beginning of a given array. It changes the length of the array.
syntex: unshift(element0, element1)
Example: const arr = [3, 8, 10, 11];
console.log(arr.unshift(5, 7));
console.log(arr)
output: [5, 7, 3, 8, 10, 11]
10. Array.map()
This method iterate over an array and return a modified array using callback function.
The callback function will then be executed on each of the array elements.
syntex: Array.map()
Example: const arr = [3, 7, 10, 13];
const map1 = arr.map(x => x * 3);
console.log(map1);
output: [ 9, 21, 30, 39 ]