Masum Billal Dipu
2 min readMay 6, 2021

--

Here I want to discuss array method in javaScript
• Sort()
When we want sort out an array alphabetically .We need to use sort method.
Example:
Var arr=[“Samad”,”Barek”,”Ahad”];
Console.log(arr.sort()) // arr=[“Ahad”,”Barek”,”Samad”];
• reverse()
When we want to reverse array of value from this array than we use reverse method.
Example:
Var arr=[“Samad”,”Barek”,”Ahad”];
Console.log(arr.reverse()) // arr=[“Ahad”,”Barek”,”Samad”];
• push()
When we want to insert new value after the last value in array that time we use push method.
Example:
Var arr=[“Samad”,”Barek”,”Ahad”];
Console.log(arr.push (“Mir”)) // arr=[“Samad”,”Barek”,”Ahad”,”Mir”];
• pop()
When we want to remove last element from the array than we use pop method.
Example:
var arr=[“Samad”,”Barek”,”Ahad”,”Mir’];
Console.log(arr.push (“Mir”)) // arr=[“Samad”,”Barek”,”Ahad”];
• Length
If we want to get length that time we use array.length method.
Example:
var arr=[“Samad”,”Barek”,”Ahad”,”Mir’];
console.log(arr.length) // 4
• shift()
if I want to remove first element from an array I need to use shift method.
Example:
var arr=[“Samad”,”Barek”,”Ahad”,”Mir’];
console.log(arr.shift()) // Samad
console.log(arr) // arr=[”Barek”,”Ahad”,”Mir’];

• unshift()
When we want to insert new value in starting element of an array that time we use unshift method.
Example:
var arr=[“Samad”,”Barek”,”Ahad”];
Console.log(arr.unshift (“Mir”)) // arr=[“Mir”,“Samad”,”Barek”,”Ahad”];

• sclice()
Let I have an array and I want to slice it than I need to use slice method.
Example:
var num=[10,20,30,40,50,60,70]
console.log(num.slice(0,4))/ / num=[10,20,30,40]
here 0 is starting index and 4 is length
• splice()
Let I have an array and I want to slice it than I need to use slice method.
Example:
var num=[10,20,30,40,50,60,70]
console.log(num. splice (3,7))/ / num=[10,20,30,40]
here 0 is starting index and 7is how many element you want

• map()
If any one want to traverse an array they can use map method.
Example:
Let I have an array,
var num=[10,20,30,40,50,60,70]
num.map(item=>{
console.log(item)
}
// all array value print one by one

• find()
If any one want to find element from array need to use find method.by find method only get first match value.
var nums=[10,20,30,40,30,50,60,70]
num.find(item=>item===30 && console.log('get value')) // get value

• filter()
If any one want to get all match element from the array.they need to use filter method.
Example:
var num=[10,20,30,40,50,30,60,70]
num.filter(item=>item===30 && console.log(item))
// 30
//30

--

--