More Array Methods

Size
2,327 Kb
Views
2,024

How do I make an more array methods?

What is a more array methods? How do you make a more array methods? This script and codes were developed by Martin Baillie on 25 January 2023, Wednesday.

More Array Methods Previews

More Array Methods - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>More Array Methods</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>

More Array Methods - Script Codes JS Codes

'use strict';
/*
Array.isArray(obj)
var new_arr = arr.concat(value1[, value2[, ...[, valueN]]])
var boolean = arr.every(function(currentValue[, index[, array])[, thisArg])
var arr = arr.fill(value[, start = 0[, end = this.length]])
var new_arr = arr.filter(function(element[, index[, array])[, thisArg])
var value || undefined = arr.find(function(element[, index[, array])[, thisArg])
*/
var cl = console.log;
console.clear();
var a = [1,2,3,4,5];
var b;
var c;
var d;
var obj = {};
cl('a.length', a.length);
cl('b = a.slice() new arr', b = a.slice());
cl('b', b);
cl('a', a)
cl('a.pop() el removed', a.pop())
cl('a', a);
cl('b', b)
cl('a.push(el,..) length', a.push(5,6));
cl('a', a);
cl('a.shift() el removed', a.shift())
cl('a', a)
cl('a.unshift(el,..) length', a.unshift(1));
cl('a', a);
cl('a.forEach(function (item, index, array) { ... }, thisArg) returns undefined', a.forEach(function (item, index, array) { this['index' + index] = item; }, obj)
);
cl('Result of forEach()', obj);
cl('a.find(function (item, index, array) { ... }, thisArg) returns item', a.find( function ( item, index, array) { return item === 3; }, obj)
);
cl('a.every(function ( item, index, array) { ... }, thisArg) returns boolean', a.every(function (item, index, array) { return item < 10; }, obj)
);
cl('a.filter(function ( item, index, array) { ... }, thisArg) returns array', a.filter(function(item, index, array) { return item >= 3; }, obj)
);
cl('a.findIndex(function ( item, index, array ) { ... }, thisArg) returns index', a.findIndex(function(item, index, array) { return item === 3; }, obj)
);
d = [1,4,9];
cl('a.map(function ( item, index, array ) { ... }, thisArg) returns new array', d.map(Math.sqrt), d.map(function( item, index, array ) { return item * 2; }, obj ), d
);
c = [3,2,1,5,4];
cl('a.sort([function(a,b)]) returns new array (modifies array)', c.sort(function(x,y) { return x - y}), // callback function required for numbers c.sort( (x, y ) => x - y ), c
);
cl('a.reduce(function( previousValue, currentValue, currentIndex, array } { ... }, initialValue) returns reduction value)', a.reduce( function (previousValue, currentValue, currentIndex, array ) { return previousValue - currentValue; }), a.reduce( (prev, curr, i, arr) => prev - curr)
);
cl('a.reduceRight(function( previousValue, currentValue, currentIndex, array } { ... }, initialValue) returns reduction value)', a.reduceRight( function (previousValue, currentValue, currentIndex, array ) { return previousValue - currentValue; }), a.reduceRight( (prev, curr, i, arr) => prev - curr)
);
cl('a.reverse() returns new array (modifies array)', a.reverse());
cl('a.toString() returns comma separated string', a.toString());
cl('a.join(separator = \',\') returns string', a.join(), a.join('|'), a.join(', '), a.join('')
);
cl('a.indexOf(el[, fromIndex]) index || -1', a.indexOf(2, 2));
cl('a.lastIndexOf(searchElement[, fromIndex = arr.length - 1]) returns index || -1', a.lastIndexOf(5, a.length-2)
);
cl('a.includes(searchElement[, fromIndex]) returns boolean', a.includes(5,1)
);
b = a.slice();
cl('a.splice(start, deleteCount[, item1[, item2[, ...]]]) returns deleted elements (modifies array)', b.splice(0, 2, 8, 9), b
);
cl('a.fill(value[, start = 0[, end = this.length]]) returns modified array (modifies array)', a.fill(5, 1, a.length - 1), Array(3).fill(4)
);
More Array Methods - Script Codes
More Array Methods - Script Codes
Home Page Home
Developer Martin Baillie
Username martin42
Uploaded January 25, 2023
Rating 3
Size 2,327 Kb
Views 2,024
Do you need developer help for More Array Methods?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Martin Baillie (martin42) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!