JavaScript - array methods

revision:


list of methods and description

Array.from() : converts an array like object to an array.

concat() : returns a new array comprised of this array joined with other array(s) and/or value(s).

copyWithin() : copies a part of the same array within the same calling array.

entries() : returns a new Array Iterator object that contains the key/value pairs for each index in the array.

every() : returns true if every element in this array satisfies the provided testing function.

fill() : returns a modified array by filling a specified index with the specified value.

filter() : creates a new array with all of the elements of this array for which the provided filtering function returns true.

find() : returns the first value of the array elements which satisfies the provided condition.

findIndex() : returns the index value of the element, not the value itself.

forEach() : calls a function for each element in the array.

includes() : determines whether certain values exist in the array or not. If the value exists in the array then the method returns true else return false.

indexOf() : rReturns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.

isArray() : returns true if the passed argument is an array else returns false.

join() : joins all elements of an array into a string.

lastIndexOf() : returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.

map() : creates a new array with the results of calling a provided function on every element in this array.

pop() : removes the last element from an array and returns that element.

push() : adds one or more elements to the end of an array and returns the new length of the array.

reduce() : applies a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.

reduceRight() : applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.

reverse() : reverses the order of the elements of an array -- the first becomes the last, and the last becomes the first.

shift() : removes the first element from an array and returns that element.

slice() : extracts a section of an array and returns a new array.

some() : returns true if at least one element in this array satisfies the provided testing function.

sort() : sorts the elements of an array

splice() : adds and/or removes elements from an array.

toSource() : represents the source code of an object

toString() : returns a string representing the array and its elements.

unshift() : adds one or more elements to the front of an array and returns the new length of the array.

values() : returns a new array iterator that contains values of each index in the array.


examples:

























code:
                <div>
                    <a id="array1"></a><br><br>
                    <a id="array2"></a><br><br>
                    <a id="array3"></a><br><br>
                    <a id="array4"></a><br><br>
                    <a id="array5"></a><br><br>
                    <a id="array6"></a><br><br>
                    <a id="array7"></a><br><br>
                    <a id="array8"></a><br><br>
                    <a id="array9"></a><br><br>
                    <a id="array10"></a><br><br>
                    <a id="array11"></a><br><br>
                    <a id="array12"></a><br><br>
                </div>
                <script>
                    var students = [ 'Jack', ' James', ' Robert', ' John', ' Lea', ' Christine', ' Thea'];
                    document.getElementById("array1").innerHTML = "students array : " + students;
                    students.pop();
                    document.getElementById("array2").innerHTML = "pop() effect: " + students;
                    students.shift();
                    document.getElementById("array3").innerHTML = "shift() effect: " + students;
                    students.push(' Oscar', ' Brigitte');
                    document.getElementById("array4").innerHTML = "push() effect: " + students;
                    students.unshift("Peter");
                    document.getElementById("array5").innerHTML = "unshift() effect: " + students;
                    var length = students.length;
                    document.getElementById("array6").innerHTML = "length property: " + length;
                    students.splice(3,2, ' Teddy', ' Eric')
                    document.getElementById("array7").innerHTML = "splice() effect: " + students;
                    var newStudent = students.slice(4,6)
                    document.getElementById("array8").innerHTML = "slice() effect: " + newStudent;
                    var others = ['Wim', 'Alice']
                    var all = students.concat(others);
                    document.getElementById("array9").innerHTML = "concat() effect: " + all;
                    document.getElementById("array10").innerHTML = "toString() effect: " + students.toString();
                    var minus = delete students[0];
                    document.getElementById("array11").innerHTML = "delete() effect: " + students;
        
                </script>