Must To Know Array Methods in Javascript - DEV Community ? ?? ? PDF
Must To Know Array Methods in Javascript - DEV Community ? ?? ? PDF
Ritik
3
in Javascript + FOLLOW
location
Ritik Apr 12 ・4 min read
India
Array are mostly used in web development and most of the task on web
need Array along with its methods. In JavaScript, arrays have many More from @ritik_dev_js
predefined methods in its _proto_.So lets discuss some commonly used Closure, Currying and IIFE in
array methods along with their purpose. JavaScript
#javascript #react #angular #vue
Rapidtext multipurpose
sms/bulk sms app for alert &
commercial purpose
function greater_than_20(item){ #twiliohackathon #javascript #node
return item > 20; #deshowdev
}
const all_numbers = [2,4,5,7,20,23,15,9]; Trying to Understand How
const found = all_numbers.find(greater_than_20);
Node Loads Modules
console.log(found);
#node #javascript #todayilearned
//23
#books
Is TypeScript Really... A
Language??
function greater_than_20(item,index,array){
if(item>20 && index>4){ #javascript #typescript #react
2. Array.filter()
The filter() method takes each element of array and check the condition
provided in callback function and creates a new array of those
elements that satisfies the condition. If no element satisfies then a empty
array is returned.
Lets see the code :
3. Array.forEach()
The forEach() method just runs a function for each element of array. It does
not return anything i.e. undefined.
It is same like for loop.
4. Array.map()
The map() method runs a function for each element of array just like
forEach() method but it also creates a new array of result, of each element.
5. Array.reduce()
The reduce() method executes a reducer function on a provided array
elements and returns a single output value.
A reducer function is a special one. It uses two arguments accumulator and
currentValue. The result of each iteration is stored in
accumulator.
Lets see an example :
6. Array.sort()
The sort method sorts the elements of the provided array. By default it sorts
in ascending order.
We can change the sort order according to our use by passing a callback
funtion.
Lets sort the "debts" array in descending order.
7. Array.slice()
The slice methods returns a portion of array into a new array. It takes two
parameters as index value - begin and end.
"End index value is not included".
8. Array.splice()
The splice method is used to alter the array. It helps in deleting or adding
items inside a array at
any particular position. It returns the array with deleted items.
It takes 3 parameter starting index , delete count from that index , and if
something to add after that index.
Sign Up Now
Ritik + FOLLOW
PREVIEW SUBMIT
84 27
24
Object Destructuring in
ES6
Sarah Chima
Sarah Chima
124 15 + FOLLOW
Properties
Nick Scialli (he/him) - Apr 21