Basically Array is used to store multiple values in a single variables(only store a fixed size sequential collection of same type of element) .
Syntax ->
var names = new Array( "Mukesh" , "Ravi");
Parameter of an Array can be a list of string or integers . And array allowed maximum length is 4,292,967,297 .
If you want to access the array elements then you can easily access by square bracket .
names[0] //return first element i.e Mukesh
names[1] //return first element i.e Ravi
Properties ->
There are mainly two properties in an array ->
1) Array.constructor -> It specifies the function that creates an object prototype .
2) Array.lenght ->If reflects the number of elements in an array .
Methods ->
There are 3 type of methods in an array ->
1) Mutator methods ( method that modify an array )
2) Accessor methods ( method doesn't modify the array and return some new array )
3) Iteration methods ( when length of an array is sampled and changes to the array i.e set the value and delete the element)
1) Mutator methods ( method that modify an array )
It contains 9 method :
1.1) Array.copyWithin() :-> Copy a sequence of an array elements within the array .
1.2) Array.fill() :-> Fill all the elements of an array from start index to end index .
1.3) Array.pop() :-> Remove the last elements from an array and return that(removed) element .
1.4) Array.push() :-> Add one or more elements to the end of an array and return the new length of an array.
1.5) Array.reverse() :-> Used to reverse the order of the elements of an array i.e first becomes the last element and vice versa .
1.6) Array.shift() :-> Removes the first element from an array and return that element .
1.7) Array.sort() :-> Sorts the elements of an array and return the array .
1.8) Array.splice() :-> Add or remove the elements from an array .
1.9) Array.unshift() :-> Add one or more elements to the front of an array and return the new length of an array .
2) Accessor methods ( method doesn't modify the array and return some new array )
It also contains 9 method :
2.1) Array.concat() :-> Returns a new array after joined with other array .
2.2) Array.include() :-> It return true or false after determining whether an array contain a certain element is or not .
2.3) Array.join() :-> It joins all elements of an array into a string .
2.4) Array.slice() :-> Extract/remove a certain section of an array and return a new array .
2.5) Array.toSource() :-> Used to create a new array .
2.6) Array.toString() :-> Return a string which represent the array and its element .
2.7) Array.toLocalString() :-> Return a localized string which represent the array and its element .
2.8) Array.indexof() :-> Return the first(least) index of an element within the array equal to the specified value or return -1 if none is found .
2.9) Array.lastIndexof() :-> Return the last(greatest) index of an element within the array equal to the specified value or return -1 if none is found .
3) Iteration methods ( when length of an array is sampled and changes to the array i.e set the value and delete the element)
It contains mainly 9 methods :
3.1) Array.forEach() :-> It is used to call a function for eache element in an array .
3.2) Array.entries() :-> It contain key and their value for each index in an array and return a new array .
3.3) Array.every() :-> It test the given condition and return true if condition is true .
3.4) Array.some() :-> It test the given condition , if at least one element satisfy the given condition, is true it will return true .
3.5) Array.filter() :-> It will create a new array after filtering the function ,return if true .
3.6) Array.find() :-> If an element in the array match the given condition then it return the found value in an array .
3.7) Array.keys() :-> It will return a new array that contain keys for each index in the array .
3.8) Array.values() :-> It will return a new array that contain value for each index in the array .
3.9) Array.map() :-> It will create a new array after maping each element .
0 Comment(s)