array's tag archives

Sorting a two dimensional array in javascript

Sorting arrays in JavaScript is done via the method array.sort(). Passing in a function reference into array.sort() As touched on already, array.sort() accepts an optional parameter in the form of a function reference (lets call it sortfunction). The format of this function looks like this: When such a function is passed into array.sort(), the array elements are sorted based on the relationship between each pair of elements "a" and "b" and the function's return value. The three poss...

Javascript Equivalent of PHP’s explode() and implode()

Do you know javascript has equivalent functions as php's explode() and implode(). Let's say we have a string: We want to break down each number into an array called $num_array. In PHP we could do this: The PHP implode function would produce the following: In Javascript, we can use split function. Then let's say we wanted to piece it back into the original string. We could just do this in php: $string = implode(':',$explode_array); In Javascript, we c...