
String.prototype.toLowerCase(): this method converted the string into lowercase.
Example: myStr = “Hello Its Zihad”
console.log(myStr.toLowerCase(myStr)) => “hello its zihad”
String.prototype.slice():make a new section of string from mother string.
Example: myStr = “i love Bangladesh”
console.log(myStr.slice(7, 17)) => “Bangladesh”
String.prototype.split():divide a string depends on split character.
Example: myStr = “why so serious ”
console.log(myStr.split(“ ”)) => [“why”, “so”, “serious”]
String.prototype.trim(): this method is used for trim a string. Trim space means delete whitespace from a string.
Example: myStr = “ hi its zihad. ”
console.log(myStr) => “ hi its zihad. ”
`console.log(myStr.trim()) => “”hi its zihad.”
Number.isNaN(): this method checks the value isNaN and the type is number.
Example: myNumber = “A0F”
console.log(Number.isNaN(myNumber)) => NaN
- Reverse (): used by the method can change the array element's position. Its work on the array the last element came to the first position and continues until all elements can change position.
- array.slice: array.slice copies the whole array or copies some certain elements of the array and returns a new array. The method can have the following syntax.
array.slice(); // copies the whole array.
array.slice(start); // copies elements from the start index.
array.slice(start,end); // copies elements from the start index upto end excluding the element of the end index.
let newFoods = foods.slice();
console.log(newFoods); // ["Guava", "Orange", "Banana", "Mango", "Grape"]
newFoods = foods.slice(2);
console.log(newFoods); // ["Banana", "Mango", "Grape"]
newFoods = foods.slice(2,4);
console.log(newFoods); // ["Banana", "Mango"]
- array.splice: array.splice removes elements from the array or replaces them by adding new elements in place. The method can have the following syntax.
array.splice(start); // removes all element from the starting index.
array.splice(start,deleteCount); // removes element from the starting index equivalent to deleteCount.
array.splice(start, deleteCount, item); // replaces deleteCount element at starting index.
foods.splice(2); // ["Guava", "Mango"]
console.log(foods);
foods.splice(1,2);
console.log(foods); // ["Guava", "Mango", "Grape"]
foods.splice(2,1,"Apple");
console.log(foods); //["Guava", "Orange", "Apple", "Mango", "Grape"]
- How to add a new item in Array from last using push() method
if you have an Array with some items and now you want to add a new item in this array after the last element of an Array.
then you should call the push() method. push() method adds a new element in Array after the last element of an Array.
First, create an Array-like :
var Names = [‘Ragnar’, ‘Bjorn’, ‘Ubbe’, ‘Hviserk’];
if you want to add a new name in this array after ‘Hvitserk’ then you should call arrayName.push() method and pass a parameter and console this array Name.
Example:
// Output: (5) [“Ragnar”, “Bjorn”, “Ubbe”, “Hviserk”, “Ivar”]
- How to remove an item in Array from last using pop() method
if you have an Array with some items and now you want to Remove the last item from this array.
then you should call the pop() method. the pop() method removes the last item from Array.
First, create an Array-like :
var Names = [‘Ragnar’, ‘Bjorn’, ‘Ubbe’, ‘Hviserk’, ‘ivar’];
if you want to Remove ‘ivar’ from this array then you should call arrayName.pop() method and you don’t have to pass any parameter and console this array Name.
Example:
// Output: (4) [“Ragnar”, “Bjorn”, “Ubbe”, “Hviserk”]
- Shift(): This method simply removes the first element from an array. It also returns the removed element. And, obviously, it changes the length of the array.
const arr = [15, 20, 43, 55, 48];
const firstElement = arr.shift();
console.log(arr);
// expected output: Array [20, 43, 55, 48]
console.log(firstElement);
// expected output: 15
- Unshift(): This method is the opposite of the shift() method. shift() removes the first element from an array, right? But unshift() adds one or more elements at the beginning of an array where push() adds one element at the end of the array. It also returns the new length of the array.
const arr = [4, 5, 6, 7];
const newSize = (arr.unshift(1, 2, 3));
console.log(newSize);
// expected output: 7
console.log(arr);
// expected output: Array [1, 2, 3, 4, 5, 6, 7]