Let’s touch JavaScript
As JavaScript is getting more and more popular, teams are leveraging its support on many levels in their stack — front-end, back-end, hybrid apps, embedded devices and much more.
# 1.String. prototype. slice()
String.prototype.slice() method new returns a string without changing the original string
const word = ‘Success usually comes to those who are too busy to be looking for it.’;
console.log(word.slice(8, 21));
// expected output: “usually comes”console.log(word.slice(25));
// expected output: “those who are too busy to be looking for it.”console.log(word.slice(-8));
// expected output: “ for it.”
#2.String.prototype.replace()
String.prototype.replace() method used to change special parts without changing the inside of any spring
const p = ‘Try not to become a person of success, but rather try to become a person of value’;
console.log(p.replace(‘success’, ‘win’));
// expected output: ”Try not to become a person of win, but rather try to become a person of value”
#3.String.prototype.substring()
String.prototype.substring()method that mainly used to return a string between start and end indexes.
const str = ‘I am Nishat Ahmed’;
console.log(str.substring(4, 11));
// expected output: “Nishat”console.log(str.substring(5));
// expected output: “Nishat Ahmed”
#4.Number.prototype.toFixed()
it is a method formats a number using fixed-point notation.
function acounts(p) {
return Number.parseFloat(p).toFixed(2);
}console.log(acounts(88.1368));
// expected output: “88.14”
#5.Array.prototype.filter()
The filter() method creates a new array containing only the elements that “pass the test” implemented by the callback function. we call this type of callback a predicate function
const numbers = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’];
const even = numbers.filter(number => number % 2 === 0);
console.log(even);
// expected output: Array [“2”, “4”, “6”]
#6.Array.prototype.find()
This method will stop at first element that pass the test and return that. if no exists ,it will return undefined
const array1 = [1,2,3,4,5,6,7];
const result = array1.find(element => element > 3);
console.log(result);
// expected output: 4
#7.Array.prototype.forEach()
The callback function does not expect a return value, and the forEach()method it also returns undefind
const numbers = [‘3’, ‘4’, ‘5’];
numbers.forEach(element => console.log(element));
// expected output: “3”
// expected output: “4”
// expected output: “5”
#8.Array.prototype.map()
This method creats a new array populated with the return value of the call back function forEach element in the array.
const numbers = [6, 9, 15, 50];
// pass a function to map
const even = numbers.map(x => x * 3);console.log(even);
// expected output: Array [18, 27, 45, 150]
#9.Array.prototype.every()
This method takes a predicate function and returns true if all of the elements in the array.
const Test = (currentValue) => currentValue < 30;
const result = [60, 30, 39, 70, 10, 13];
console.log(result.every(Test));
// expected output: false;
#10.Array.prototype.flat()
This method creats a new array with all sub array elements into it.
const numbers = [0, 1, 2, [5, 7]];
console.log(numbers.flat());
// expected output: [0, 1, 2, 5,7]const even = [0, 1, 2, [[[3, 4]]]];
console.log(even.flat(1));
// expected output: [0, 1, 2, [3, 4]]