Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

TOP Array Methods

ARRAY		  	 METHOD					DESCRIPTION
[1, 2, 3]		.push(4); 		inserts el. @ end of array	  	  // [1, 2, 3, 4]
[1, 2, 3]		.pop();   		removes el. @ end of array		  // [1, 2]
[1, 2, 3]		.shift(); 		removes el. @ beginning of array  // [2, 3]
[1, 2, 3]		.unshift(0); 	inserts el. @ beginning of array  // [0, 1, 2, 3]
['a', 'b']		.concat('c'); 	concatenated 2 diff. arrays 	  // ['a', 'b', 'c']
['a', 'b', 'c']	.join('-'); 	the argum. determine whats btw the array el.s // a-b-c
['a', 'b', 'c']	.slice(1); 		1st argum. the index, 2nd argum amount to be removed	// ['b', 'c']
['a', 'b', 'c']	.indexOf('b'); 	give the index on an el. in the array	// 1
['a', 'b', 'c']	.includes('c'); bool, is the argum in the array?  // true
[3, 5, 6, 8]	.find((n) => n % 2 === 0); 						  // 6
[2, 4, 3, 5]	.findIndex((n) => n % 2 !== 0); 				  // 2
[3, 4, 8, 6]	.map((n) => n * 2); basically looping in arrays	  // [6, 8, 16, 12]
[1, 4, 7, 8]	.filter((n) => n % 2 === 0); 					  // [4, 8]
[2, 4, 3, 7]	.reduce((a, b) => a + b);		 				  // 16
[2, 3, 4, 5]	.every((x) => x < 6); 							  // true
[3, 5, 6, 8]	.some((n) => n > 6); 							  // true
[1, 2, 3, 4]	.reverse(); 									  // [4, 3, 2, 1]
[3, 5, 7, 8]	.at(-2); 										  // 7	
 
PREVIOUS NEXT
Tagged: #TOP #Array #Methods
ADD COMMENT
Topic
Name
3+7 =