JavaScript Basic

Mehedi Hasan
2 min readMay 5, 2021

--

1. JavaScript array find() method

Const numbers = [9, 12, 16, 20, 7, 8, 17, 15]

how to get value like 16 in the array?

Example:

Const getOne = numbers.find( num => element > 15 );

Console.log(getOne)

You can get output 16

2. JavaScript array filter() method

Const fruits = [“banana”, “orange”, “apple”, “mango”, “jackfruit”, “Lemon”]

How to get specific fruits length in array using filter method?

Example:

Const fruitsLength = fruits.filter( fruit => fruit.length > 5 );

Console.log(fruitsLength)

Get output = (“banana”, “orange”, “jackfruit”)

3.Another filter() method

Const numbers = [3, 9, 5, 13, 18, 20, 7, 4]

There is 8 numbers in array. How to get valus in the array less than 9 removed.

Const filterd = numbers.filter(num => num > 9 );

Console.log(filterd)

You can get output = (13, 18, 20)

4. JavaScript push() method

How to add new elements in the array.

Simple example:

Const device = [“mobile”, “watch”, “television”, “laptop”]

Const newDeviceAdd = device.push(“bike”, “car”)

Console.log(newDeviceAdd)

//expected output = [“mobile”, “watch”, “television”, “laptop”, “bike”, “car”]

5.JavaScript pop() method

How to removes the last element in the array

Example:

Const car = [“role roys”, “ferari”, “tesla”, “audi”, “tata”]

Const removes = car.pop()

Console.log(removes)

Output = [“role roys”, “ferari”, “tesla”, “audi”]

5. JavaScript array.toString() method

toSrting() method using the specific array

example:

const elements = [ 3, “ab”, “avx”, 10, 332]

const underElements = elements.toString()

console.log(underElements)

output = [“3, ab, avx, 10, 332”]

6. JavaScript reduce() method

How to work reduce method work that example

Const numbers = [7, 8, 9, 10]

Const reducer = (accumulator, currentValue) => accumulator + currentValue;

Const addingNumber = numbers.reduce(reducer)

Console.log(addingNumber)

Output = 34

Also more than example:

Const addingNumberTwo = numbers.reduce(reducer, 6);

Console.log(addingNumbersTwo)

Output = 40

7. JavaScript slice() method

Slice() method is using for collect soecific array elements

Example:

Const friends = [“boni”, “hafijul”, “monir”, “areful”, “ripon”]

Const findFriends = friends.slice(3)

Console.log(findFriens)

Output result = [“aredul”, “ripon”]

Also more than example:

Const findFriends = friends.slice(2, 4)

Console.log(findsFriend)

Output result = [“monir”, “areful”, “ripon”]

8. JavaScript String

Simple string example:

Const text = “mehedihasanibnc”

Const textNumber = text.length

Console.log(textLength)

Output result = 14

9. JavaScript toUpperCase() Method

The toUpperCase() method are using in string text letter uppercase

Example:

const sentence = ‘I am the stude of programming hero’;

const uppercase = sentence.toUpperCase()

console.log(uppercase)

output result = “I Am The Student Of Programming Hero”

10. JavaScript toLowerCase() Method

The toUpperCase() method are using in string text letter uppercase

Example:

const sentence = ‘I AM THE STUDENT OF PROGRAMMING HER’;

const lowercase = sentence.toLowerCase()

console.log(lowercase)

output result = “‘i am the stude of programming hero’”

--

--