[Go to site: main page, start]

0% found this document useful (0 votes)
1 views1 page

JavaScript Array Methods With Examples

The document provides a comprehensive overview of JavaScript array methods, including their syntax, examples, and outputs. Each method, such as push, pop, shift, and others, is briefly explained with corresponding code snippets. This serves as a quick reference guide for developers to understand and utilize various array functionalities in JavaScript.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

JavaScript Array Methods With Examples

The document provides a comprehensive overview of JavaScript array methods, including their syntax, examples, and outputs. Each method, such as push, pop, shift, and others, is briefly explained with corresponding code snippets. This serves as a quick reference guide for developers to understand and utilize various array functionalities in JavaScript.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Array Methods with Examples

Method Syntax Example Output/Purpose

push [Link](x) let a=[1,2]; [Link](3) [1,2,3]


pop [Link]() [1,2,3].pop() Returns 3
shift [Link]() [1,2,3].shift() Returns 1
unshift [Link](x) let a=[2]; [Link](1) [1,2]
concat [Link](b) [1].concat([2,3]) [1,2,3]
slice [Link](s,e) [1,2,3,4].slice(1,3) [2,3]
splice [Link](i,n,...x) let a=[1,2,3]; [Link](1,1,9) [1,9,3]
indexOf [Link](x) [1,2,3].indexOf(2) 1
lastIndexOf [Link](x) [1,2,2].lastIndexOf(2) 2
includes [Link](x) [1,2].includes(2) true
find [Link](fn) [1,4,7].find(x=>x>3) 4
findIndex [Link](fn) [1,4,7].findIndex(x=>x>3) 1
filter [Link](fn) [1,2,3].filter(x=>x>1) [2,3]
map [Link](fn) [1,2].map(x=>x*2) [2,4]
forEach [Link](fn) [1,2].forEach([Link]) Iterates
reduce [Link](fn,init) [1,2,3].reduce((a,b)=>a+b,0) 6
reduceRight [Link](fn) [1,2,3].reduceRight((a,b)=>a-b) 0
some [Link](fn) [1,2,3].some(x=>x>2) true
every [Link](fn) [2,4].every(x=>x%2===0) true
sort [Link]() [3,1,2].sort() [1,2,3]
reverse [Link]() [1,2,3].reverse() [3,2,1]
join [Link](sep) ["a","b"].join("-") "a-b"
flat [Link]() [1,[2,[3]]].flat(2) [1,2,3]
flatMap [Link](fn) [1,2].flatMap(x=>[x,x]) [1,1,2,2]
fill [Link](v) [1,2,3].fill(0) [0,0,0]
copyWithin [Link](t,s) [1,2,3,4].copyWithin(1,2) [1,3,4,4]
at [Link](i) [10,20,30].at(-1) 30
toString [Link]() [1,2,3].toString() "1,2,3"

You might also like