


1 being the last element of the array, -2 being the next to last and so on. Note: Both start and end can be negative integers, which just denotes that they're enumerated from the end of the array. Var combinedString = arr.reverse("=")Ĭonsole. slice (start, end) - Returns a part of the invoked array, between the start and end indices. The elements will be separated by a specific separator while joining the array elements, which will be passed while calling the method. Join() method is used to join the array elements into a string and return the string. prints 'jack fruit','grape','mango','kiwi','apple' join() : In such kind of case, we can sort the array in ascending order then reverse it, so we will get descending order var arr = Ĭonsole.log(arr) // prints 3, 9, 1 concat()Ĭoncat method is used to join two arrays and returns a new array consisting of the elements of both the arrays one after another.

Sometimes you might need to sort the array in descending order but we do not have such functionality in nodejs. reverse() function does not accept any parameter. Reverse() function is used to reverse the order of the array such that the first element becomes the last and the last element becomes the first. Sort method is used to arrange the elements of the array in ascending order var arr = var arr = Ĭonsole.log(arr) // prints 1, 3, 'abc', 'bbc'Ĭonsole.log(arr) // prints 1, 3 sort() function in nodejs: If the user provides an index, howMany, and values(elements) to the splice() function then splice() will insert the given details but if we do not provide value then the splice() function will remove element from the given index with howMany elements. If you don't specify any elements, splice simply removes the elements from the array. , elementN − The elements to add to the array. If howMany is 0, no elements are removed.Įlement1. HowMany − An integer indicating the number of old array elements to remove. Index − Index at which to start changing the array. Splice() function can be used in two ways i.e to either add the element into the array or remove the elements from the array.
