Introduction
JavaScript Array object is a global object that is used in the construction of arrays; which are high-level, list-like objects. Some of the important methods used with arrays are discussed in this article.
The concat() method is used to merge two or more arrays. This method does not change the existing arrays but instead, returns a new array.
- <script>
- let developer = ['arvid', 'soniya', 'priya', 'rahul'];
- let testor = ['umesh', 'kalpana', 'suresh', 'zoya'];
- let employee = developer.concat(testor);
- console.log(employee)
- </script>
The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.
- <script>
- let employee = ['arvid', 'soniya', 'priya', 'rahul', 'umesh', 'kalpana', 'suresh', 'zoya'];
- let iterator = employee.entries();
- for (let e of iterator) {
- console.log(e)
- }
- </script>
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
- <script>
- let employee = ['arvid', 'soniya', 'priya', 'rahul', 'umesh', 'kalpana', 'suresh', 'zoya'];
- console.log(employee.filter(e => e.length < 6));
- console.log(employee.filter(e => e.length > 6))
- console.log(employee.filter(e => e.length == 6))
- </script>
The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
- <script>
- let numbers = [10, 12, 15, 18, 9, 5, 22, 13, 30];
- let found = numbers.find(function (element) {
- return element > 10;
- });
- console.log(found);
- </script>
The fill() method fills (modifies) all the elements of an array from a start index (default zero) to an end index (default array length) with a static value. It returns the modified array.
- <script>
- let numbers = [10, 15, 12, 3, 4, 7, 2];
- console.log(numbers.fill(0, 1, 3))
- console.log(numbers.fill(5, 1))
- console.log(numbers.fill(6))
- </script>
The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating no element passed the test.
- <script>
- let emplyees = ['Mariya', 'priya', 'sonam', 'juliya', 'priyanka'];
- console.log(emplyees.indexOf('priya'))
- </script>
The sort() method sorts the elements of an array in place and returns the array.
- <script>
- let employee = ['arvid', 'soniya', 'priya', 'rahul', 'umesh', 'kalpana', 'suresh', 'zoya'];
- const sortemployee = employee.sort();
- console.log(sortemployee)
- </script>

Join the conversation! Your thoughts help the community grow.