1//create an array like so:
2var colors = ["red","blue","green"];
3
4//you can loop through an array like this:
5for (var i = 0; i < colors.length; i++) {
6 console.log(colors[i]);
7}
1concat(arr1,[...]) // Joins two or more arrays, and returns a copy of the joined arrays
2copyWithin(target,[start],[end]) // Copies array elements within the array, to and from specified positions
3entries() // Returns a key/value pair Array Iteration Object
4every(function(currentval,[index],[arr]),[thisVal]) // Checks if every element in an array pass a test
5fill(val,[start],[end]) // Fill the elements in an array with a static value
6filter(function(currentval,[index],[arr]),[thisVal]) // Creates a new array with every element in an array that pass a test
7find(function(currentval,[index],[arr]),[thisVal]) // Returns the value of the first element in an array that pass a test
8findIndex(function(currentval,[index],[arr]),[thisVal]) // Returns the index of the first element in an array that pass a test
9forEach(function(currentval,[index],[arr]),[thisVal]) // Calls a function for each array element
10from(obj,[mapFunc],[thisVal]) // Creates an array from an object
11includes(element,[start]) // Check if an array contains the specified element
12indexOf(element,[start]) // Search the array for an element and returns its position
13isArray(obj) // Checks whether an object is an array
14join([seperator]) // Joins all elements of an array into a string
15keys() // Returns a Array Iteration Object, containing the keys of the original array
16lastIndexOf(element,[start]) // Search the array for an element, starting at the end, and returns its position
17map(function(currentval,[index],[arr]),[thisVal]) // Creates a new array with the result of calling a function for each array element
18pop() // Removes the last element of an array, and returns that element
19push(item1,[...]) // Adds new elements to the end of an array, and returns the new length
20reduce(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going left-to-right)
21reduceRight(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going right-to-left)
22reverse() // Reverses the order of the elements in an array
23shift() // Removes the first element of an array, and returns that element
24slice([start],[end]) // Selects a part of an array, and returns the new array
25some(function(currentval,[index],[arr]),[thisVal]) // Checks if any of the elements in an array pass a test
26sort([compareFunc]) // Sorts the elements of an array
27splice(index,[quantity],[item1,...]) // Adds/Removes elements from an array
28toString() // Converts an array to a string, and returns the result
29unshift(item1,...) // Adds new elements to the beginning of an array, and returns the new length
30valueOf() // Returns the primitive value of an array
1let a = ['sam','john','ali','kahn'];
2let b = [19,23,41,61];
3let p = 'var val';
4
5// #### arrays all type to declera
6
7 let a = [34,'osama',929,'ali','kahn']; //1st to declar arry
8 let a = new Array(); //when you dont know how many is their
9
10let mlutiarry = [
11 ['osama','khan','ali'], //array in array
12 [12,45,34],
13 ['audit','val','naztown']
14];
15
16// #### arrays all type to declera
17
18 let r = Array.isArray(b); //check is arry or not
19 let c = a.includes("ali"); //check wether value is in arry or not (its case sensetive)
20
21 a.sort(); //sort all value
22 a.reverse(); //reverse all value
23
24 let st = a.toString(); //array into string
25 let st = a.join("-"); // same but without ,
26 let n = a.concat(b); //join two make one arry
27
28 a.pop(); //delete end val in array
29 a.shift(); //delete start val in arry
30
31 a.push("new"); // add new val to end
32 a.unshift("new"); //add new val to start
33
34 a[2] = "ali new"; //add modify/update value frome array any where you want
35 delete a[0]; //delete value frome array any where you want but still undefine
36
37 let n = a.slice(1,3); //slice new arry for exiting array;
38 a.splice(2,0,"osama"); //splice used to add new items to an array:
39
40 let i = a.indexOf("ali"); //give first indexof vale
41 let i = b.lastIndexOf(19); //gae last indexof vale
42
43 let res = b.some(function(age) { //if some is match retrun true
44 return age >= 18;
45})
46let res = b.every(function(age) { //if every is macth return true
47 return age >= 18;
48})
49
50let res = b.find(function (age) { //return first value
51 return age >= 29;
52})
53
54let res = b.findIndex(function (age) { //return first value indexs
55 return age >= 20;
56})
57
58let ar = [123,12,34];
59let r = ar.map(function (x) { // return new array
60 return x * 10;
61})
62document.write(res + "<br");
63
64
65
66
67
68let s = "this is an strig methods";
69let s2 = "yeh i use to it";
70let s3 = "this is end of it";
71
72
73
74 let r = s.length; //use to get length with space
75
76 let r = s.toUpperCase(); //upper all words
77 let r = s.toLowerCase(); //lower all words
78
79 let r = s.includes("an"); //return true if he find (casesensetive)
80 let r = s.startsWith("th");// return true if he find fist-word (casesen..)
81 let r = s.endsWith("ds"); //retrun true if the find last-word (cseseen..)
82
83 let r = s.search("strig"); //return index if he find (cases...)
84
85 let r = s.match(/is/g); //make new array with all same words
86
87 let r = s.indexOf("is"); //return index of first world only (casesen...)
88 let r = s.lastIndexOf("is"); //return index of last world only (casee...)
89
90 let r = s.replace("methods","function"); // replace the first value only
91
92 let r = s.trim();// trim form left to right
93
94 let r = s.charAt(5); //retrun char on string
95 let r = s.charCodeAt(5); //return unicode of char
96 let r = String.fromCharCode(65); // put unicode and return char
97
98 let r = s.concat(s2,s3); //join two string together
99
100 let r = s.split(" "); //split string and make new array
101
102 let r = s.repeat(3); //repeat same string as mush as you want
103
104 let r = s.slice(3,20); //return new string where ever you want
105 let r = s.substr(start,how many);
106 let r = s. substring(start,how many - 1);
107document.write(r);
108
109
110
111// this is an number methods######
112
113let n = 9.4356775;
114
115
116let r = Number(n); //convert string into number
117
118let r = parseInt(n); //convert decimal into int
119let r = parseFloat(n); //return with decimal num if he is
120
121let r = Number.isFinite(n); // return true int
122let r = Number.isInteger(n); return true only on int
123
124let r = n.toFixed(2); // return int with decimal as many as you want
125let r = n.toPrecision(4); // return int with decimal as many as you want +1 last decimal
126
127
128
129Math fundtion#########
130
131let r = Math.ceil(2.3); //up value 3 -2
132let r = Math.floor(2.3); // down value 2 -3
133
134let r = Math.round(3.5); //less then 5 is 3 up is 4 round
135let r = Math.trunc(3.34); //convert into integer
136
137let r = Math.min(12,423,464,3); //return min value 3
138let r = Math.max(12,423,464,3); //return max value 464
139
140let r = Math.sqrt(25); return (5)5
141let r = Math.cbrt(125); return 5(5)(5)
142
143let r = Math.pow(2,4); 2*2*2*2=16
144
145let r = Math.random(); between 0 to 1
146
147let r = Math.abs(-19); return absolut value
148let r = Math.PI; return 3.141592653589793
149document.write(r);
1dogs.toString(); // convert to string: results "Bulldog,Beagle,Labrador"
2dogs.join(" * "); // join: "Bulldog * Beagle * Labrador"
3dogs.pop(); // remove last element
4dogs.push("Chihuahua"); // add new element to the end
5dogs[dogs.length] = "Chihuahua"; // the same as push
6dogs.shift(); // remove first element
7dogs.unshift("Chihuahua"); // add new element to the beginning
8delete dogs[0]; // change element to undefined (not recommended)
9dogs.splice(2, 0, "Pug", "Boxer"); // add elements (where, how many to remove, element list)
10var animals = dogs.concat(cats,birds); // join two arrays (dogs followed by cats and birds)
11dogs.slice(1,4); // elements from [1] to [4-1]
12dogs.sort(); // sort string alphabetically
13dogs.reverse(); // sort string in descending order
14x.sort(function(a, b){return a - b}); // numeric sort
15x.sort(function(a, b){return b - a}); // numeric descending sort
16highest = x[0]; // first item in sorted array is the lowest (or highest) value
17x.sort(function(a, b){return 0.5 - Math.random()}); // random order sort
18
1<script>
2 // Defining function to get unique values from an array
3 function getUnique(array){
4 var uniqueArray = [];
5
6 // Loop through array values
7 for(var value of array){
8 if(uniqueArray.indexOf(value) === -1){
9 uniqueArray.push(value);
10 }
11 }
12 return uniqueArray;
13 }
14
15 var names = ["John", "Peter", "Clark", "Harry", "John", "Alice"];
16 var uniqueNames = getUnique(names);
17 console.log(uniqueNames); // Prints: ["John", "Peter", "Clark", "Harry", "Alice"]
18</script>
1// push - Adds value to the end of array.
2// unshift - Adds value to the start of array.
3// pop - Removes a value from the end of array and returns it.
4// shift - Removes a value from the start of array and returns it.
5// splice - Removes value/values in the 2 given indexes and returns it.
6// reverse - Reverses the array and returns it
7// sort - Sorts the array alphabeticlly
8// fill - Fills every element of the array with the given value.
9// map - Perfoms a spesific action on all elements in a array and returns it.
10// filter - Filters a array with a conditon and returns it.
11// slice - Removes value/values in the 2 given indexes and returns it.
12// concat - Combines 2 or more arrays and makes a new array and returns it
13// flat - Converts a array of arrays into a single array and returns it
14// flatMap - A combination of map and flat
15// indexOf - Locates the index of given element and returns it
16// find - filters array based on given value
17// includes - Tells if given value output is true or false and returns it.
18// some - Tells if given function output is true or false and returns it.
19// every - Tells if given statement is true for all elements in the array
20// join - joins a array on a given carecter and returns a string
21// reduce - reduces the array in a single value and returns it
22// forEach - Perfoms a spesific action on all elements in a array and returns it.
23// toString - Converts array to string seprated by commas and returns it