+
+
+
+
+ Welcome to Array Introduction!
+ This is Single page application build with HTML, CSS, Javasctipt and AJAX.
+
+
+
+
+
+
+ Convert array to string
+
+ The
+ join() method creates and returns a new string by concatenating all of the elements in an
+ array (or an
+ array-like object), separated by commas or a specified separator string. If the array has only one item, then
+ that item will be returned without using the separator.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruitsStr = fruits.join(',')
+ console.log(typeof(fruitsStr))
+ //string
+
+
+
+
+
+
+
+ Last element of the array
+
+ The length property returns the number of elements in an array. Subtracting 1 from the length of an array
+ gives the index of the last element of an array using which the last element can be accessed.
+
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ console.log(fruits[fruits.length-1])
+ //Banana
+
+
+
+
+
+
+
+ Array.prptotype.push()
+
+ The
+ push() method adds one or more elements to the end of an array and returns the new
+ length of
+ the array.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruits.push('Pineapple')
+ console.log(fruits)
+ // expected output: [ 'Apple', 'Orange', 'Kiwi', 'Mango', 'Banana', 'Pineapple'
+ ]
+
+
+
+
+
+
+
+ Array.prptotype.pop()
+
+ The
+ pop() method removes the last element from an array and returns that element. This method
+ changes the
+ length of the array.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruits.pop()
+ console.log(fruits)
+ // expected output: [ 'Apple', 'Orange', 'Kiwi', 'Mango' ]
+
+
+
+
+
+
+
+ Array.prptotype.unshift()
+
+ The
+ unshift() method adds one or more elements to the beginning of an array and returns the new
+ length of the array.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruits.unshift('Pineapple')
+ console.log(fruits)
+ // expected output: [ 'Pineapple', 'Apple', 'Orange', 'Kiwi', 'Mango', 'Banana'
+ ]
+
+
+
+
+
+
+
+ Array.prptotype.splice()
+
+ The
+ splice() method changes the contents of an array by removing or replacing existing elements
+ and/or adding new elements in place.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruits.splice(2, 1,'Cherry')
+ console.log(fruits)
+ // expected output: [ 'Apple', 'Orange', 'Cherry', 'Mango', 'Banana' ]
+
+
+
+
+
+
+
+ Array.prptotype.shift()
+
+ The
+ shift() method removes the first element from an array and returns that removed element. This
+ method changes the length of the array.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ fruits.shift()
+ console.log(fruits)
+ // expected output: [ 'Orange', 'Kiwi', 'Mango', 'Banana' ]
+
+
+
+
+
+
+
+ Array.prptotype.sort()
+
+ The
+ sort() method sorts the elements of an array in place and returns the sorted array. The
+ default sort order is ascending, built upon converting the elements into strings, then comparing their
+ sequences of UTF-16 code units values.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ console.log(fruits.sort())
+ // expected output: [ 'Apple', 'Banana', 'Kiwi', 'Mango', 'Orange' ]
+
+
+
+
+
+ Array.prptotype.reverse()
+
+ The
+ reverse() method reverses an array in place. The first array element becomes the last, and
+ the last array element becomes the first.
+
+
+
+
+ var
+ fruits = ['Apple', 'Orange', 'Kiwi', 'Mango', 'Banana']
+ console.log(fruits.reverse())
+ // expected output: [ 'Banana', 'Mango', 'Kiwi', 'Orange', 'Apple' ]
+
+