Do you know string & array prototype Javascript?
String.prototype.chartAt()
The chartAt() returns a new string method of single code located specified offset the string
chartAt(index)
Example
const word = "hellow new wordl";
console.log("The world at index is '+ word.chartAt() + '");
Run your terminal or console tab see your results
String.prototype.replace()
The replace() method returns a new string with some or all matches of a replaced. The can be a string or a and can be a string or a function to be called for each match.
replace(substr, newSubstr)
replace(substr, replacerFunction)
Example
let str = 'Twas the night before Xmas...';
let newstr = str.replace(/xmas/i, 'Christmas');
console.log(newstr);
String.prototype.toLowerCase()
The toLowerCase() method returns the calling string value converted to lower case
toLowerCase()
Example
console.log('ALPHABET'.toLowerCase());
String.prototype.toUpperCase()
The toUpperCase() method returns the calling string value converted to uppercase (the value will be converted to a string if it isn’t one).
toUpperCase()
Example
console.log('alphabet'.toUpperCase());
Array.prototype.includes()
The includes() method whether an array a certain value among it return true or false
includes(searchElement)
incluedes(searchElement, fromdex)
Example
let arr = ['a', 'b', 'c']
arr.includes('c', 3)
arr.imcluedesa('c', -100)
Array.prototype.indexOf()
The indexOf method returns the first index
indexOf(searchElement)
indexOf(searchElement, fromIndex)
Examples
var array = [2, 10, 8];
array.indexOf(2);
Array.prototype.slice()
The slice() method returns a shallow copy of a portion of an array into a new array object selected from to represent the index of items in that array. The original array will not be modified
slice()
slice(start)
slice(start, end)
Example
let fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
let citrus = fruits.slice(1, 3)
Array.prototype.forEach()
The forEach() method executes a provided function once for each array element.
forEach(callbackFn)
forEach(callbackFn, thisArg)
Example
const arraySparse = [1,3,,7]
let numCallbackRuns = 0
arraySparse.forEach(function(element) {
console.log(element)
numCallbackRuns++
})
console.log("numCallbackRuns: ", numCallbackRuns)
Array.prototype.unshift()
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
unshift(element0)
unshift(element0, element1)
unshift(element0, element1, ... , elementN)
Example
let arr = [1, 2]
arr.unshift([-7, -6], [-5])
Array.prototype.reverse()
The .reverse() method reverses an array .The first array element becomes the last, and the last array element becomes the first.
reverse()
Example
const a = [1, 2, 3];
console.log(a);
a.reverse();
console.log(a);