Today I am bringing you the fact of 10 JavaScript.

Md Mehedy Hassan
4 min readMay 5, 2021

Fact summery:

1. String.prototype.indexOf()

2. String.portotype.charAt()

3. String.prototype.toUpperCase()

4. Number.isNaN()

5. Number.parseFloat()

6. Math.random()

7. Array.prototype.filter()

8. Array.prototype.find()

9. Array.prototype.push()

10. Array.prototype.pop()

1. String.prototype.indexOf()

If I really want to write an article, I can save it in the index. This rate work is that if I want to find an article, it will tell me how many words this article contains. If I want to publish the same text again, I can do it. These first start searching for words like 0, 1, 2. The output will show the word that can be found.

Example:

const Paragraph = 'I want to full stack web developer. The work is very hard but possible. I will be a developer Inshallah';
const searchTerm = 'developer';
const indexOfFirst = paragraph.indexOf(searchTerm);
console.log(`${indexOfFirst}`);
// output: 25
console.log(`${paragraph.indexOf(searchterm, (indexOfFirst + 1))}`);
// output: 84

2. String.portotype.charAt()

This allows us to select a special number in any of the sentences and see if there is an article in that number. Then we will show only one article like a, b, x, y. Here the first number will start counting from 0. the second number will be counted as 1, this will continue.

Example:

const sentence = 'I love my country very much.'
const index = 0;
console.log(`${sentence.charAt(index)}`);
// output: I
const sentence2 = 'I want to be a full stack web developer.'
const index2 = 3;
console.log(`${sentence2.charAt(index2)}`);
// output: a
console.log

3. String.prototype.toUpperCase()

If I want to make any writing an upper case. This means that if you want to make a small letter a capital letter, then you have to use this command. All the writing can be changed id just one command.

Example:

const sentence = 'Bangladesh is our homeland.'
console.log(sentence.toUpperCase());
// output: "BANGLADESH IS OUR HOMELAND."

4. Number.isNaN()

NaN means Not A Number. If we don’t wamt to explain the number of something, we can say that it is not a Number. There are useful in many cases.

Example:

Number.isNaN(NaN);
// true
Number.isNaN('NaN');
// false
Number.isNaN(Number.NaN);
// true
Number.isNaN({});
// false

5. Number.parseFloat()

Through this a float Number is given and a number is multiplied wih it and shows him as the output. if a number is messed for any reason, then it shows NaN. The following are some examples of its rare use.

Example:

function circumference(r) {
if (Number.isNaN(Number.parseFloat(r))) {
return 0;
}
return parseFloat(r) * 5 * Math.PI ;
}
console.log(circumference('1'));
// output: 15.707963267948966

6. Math.random()

Random means different numbers will come at different times. As a result of using this random time, every time we enter a different number, we get different results every time we want to see the output. We can do it if we want to use it like a lottery.

Example:

console.log(Math.random());
// output: The value of the decimal below 0 will output.
console.log(Math.random()*5);
// output: The value of the decimal below 5 will output.
console.log(Math.random()*100);
// output:The value of the decimal below 100 will output.

7. Array.prototype.filter()

This allows me to filter any number or anything. If you want to take the big numbers of a number or you want ta take the small numbers, then you have to filter it. Many things can be done with filters. If we want to cut the duplicates into a number, we can again if we just want to keep emphasis numbers or odd numbers . If a person’s name is used twice, then they can be filtered or show big or small names.

Example:

const number = [10, 85, 65, 42, 96, 100, 36, 54];
const result = number.filter(number => number > 50);
console.log(result);
// output: [85, 65, 96, 100, 54]
const words = ['Mehedy', 'Hassan', 'Sirajul islam', 'Easin', 'Rohiz', 'Salauddin', 'Shakib', 'Mainuddin', 'Mumen'];
const result = words.filter(word => word.length > 6);
console.log(result);
// output: ["Sirajul islam", "Salauddin", "Mainuddin"]

8. Array.prototype.find()

This allows us to find a number. This means that if we give a number with a limit, then any number greater than this will show the output. If we want to find a small number again, we can do it. If we give a condition that we will take the smallest number of this number. Then only the first small number of that number will show the output.

const array = [18, 12, 25, 80, 95, 5, 16];
const found = array.find(element => element > 30);
console.log(found);
// output: 80

9. Array.prototype.push()

If we want to add a new string or number in an array, we can add it by pushing. If we are ever asked to add a number, we can add it very easily. If you ever think that another person has not been added here or need to be added then we can add here if you want. If you want to add a number, you can add it in the same way. Numbers or names or any other property can be added here.

Example:

const friends = ['Mehedy', 'Rokib', 'Easin'];
friends.push('Rohiz');
console.log(friends);
// output: ["Mehedy", "Rokib", "Easin", "Rohiz"]
friends.push('Salauddin', 'Anik');
console.log(friends);
// output: ["Mehedy", "Rokib", "Easin", "Rohiz", "Salauddin", "Anik"]
const numbers = [8, 10, 25, 36];
numbers.push(62);
console.log(numbers);
// output: [8, 10, 25, 36, 62]
numbers.push(90, 45, 5);
console.log(numbers);
// output: [8, 10, 25, 36, 62, 90, 45, 5]

10. Array.prototype.pop()

If we want to find out the last number from an array, I have to pop it. If you want to get rid of one of your friends that you are adding at last, it will become a bane as soon as you pop it. Every time you add one to the last one, it will be removed. You can remove them one by one if you want.

Example:

const friends = [ 'Kamrol', 'Sharif', 'Rokib', 'Easin', 'Mehedy', 'Hassan'];
friends.pop();
console.log(friends);
// output: ["Kamrol", "Sharif", "Rokib", "Easin", "Mehedy"]
const numbers = [ 1, 52, 62, 32, 15, 10];
numbers.pop();
console.log(numbers);
// output: [1, 52, 62, 32, 15]
numbers.pop();
console.log(numbers);
// output: [1, 52, 62, 32]

--

--