Abu Bakor Siddik
3 min readMay 5, 2021

--

Some Important Array Methods of an array we need to know :

Find: It is a builtin method.When we want to find a particular elements in a particular condition, we use find methods. When it gets the true value it will break ,it will not go for any farther iteration

const array = [2,4,67,5];

const result = array.find(element => element > 4);

console.log(result); // 6

FindIndex: It works exactly like find method.But the different between find method and findIndex method is, find method returns the main element of an array and findIndex method returns index number of the particular array element .If findIndex method dose not get the particular element it returns -1.

const array = [2,4,6,7,5,];

const result = (element) => element > 2;

console.log(array.findIndex(result));

// 1

Filter: It is also similar as find method .But it returns all the values according to condition. It means inspite of getting the first value it dose not break the iteration. .So it’s returns a new array and also it dose not change the main array.

const array = [2,4,6,7,5,];

const result = (element) => element > 2;

console.log(array.filter(result)); // [4,6,7,5]

console.log(array); // [2,4,6,7,5,]

Slice: When we slice an array element by using slice method , it takes the start index and end index value of an array. It means it will cut first at start index and then end index and it will return the value between those two index. It also returns a new array and also it dose not change the main array.

const array =[2,4,6,7,8]];

const result = array.slice(2, 4));

console.log(result); // [6,7]

console.log(array); // [2,4,6,7,8]

Splice: When will use splice methode? When in an array from the particular palace we want to add an another arry or some particular elements wants to bring out ,In that case we will use splice methode. It can takes 3 parameter ,first from where it will start cuttinf,second how many elements it will remove and last adding element.But splice it’s kind of an operation to an array.which changes tah main array

const array =[1,2,3,4,5];

const result = array.splice(1,2,10,20,11);

console.log(result); // [2,3]

console.log(array); // [1,10,20,11,4,5]

Map: It is a very important method in an array.Specially for them , who works on React.js . Map works as like for loop. It basically map each element and run for for each element . also returns a new array

var number = [1,2,3,4,5];

var result= number.map((num) => {

Return 2*num ;

}

console.log(result); // [2,4,6,8,10]

console.log(number); // [1,2,3,4,5];

Some Important String Methods of an array we need to know :

CharAt: By using this method we can print the particular element of an array from index number.

var str = “HELLO WORLD”;

var result = str.charAt(0);

console.log(result); // E

Concat: in this string method, we can merge two string in to one string

var str = “HELLO”;

var str1 = “WORLD”;

var result = str.concat(str1);

console.log(result); // HELLO WORLD

ToUpperCase : With this string method we can convert a particular string into upper case

var str = “bangladesh”;

var result = str.toUpperCase();

console.log(result); // BANGLADESH

ToLowerCase : With this string method we can convert a particular string into lower case

var str = “bangladesh BANGLADESH”;

var result = str.toLowerCase();

console.log(result); //bangladesh

--

--