Skip to content

Javascript Array.sort implementation?

Which algorithm does the JavaScript Array#sort() function use? I understand that it can take all manner of arguments and functions to perform different kinds of sorts, I’m simply interested in which algorithm the vanilla sort uses. Answer I’ve just had a look at the WebKit (Chrome, Safari …) sourc…

Calculate last day of month

If you provide 0 as the dayValue in Date.setFullYear you get the last day of the previous month: There is reference to this behaviour at mozilla. Is this a reliable cross-browser feature or should I look at alternative methods? Answer Output differences are due to differences in the toString() implementation,…

How to program a text search and replace in PDF files

How would I be able to programmatically search and replace some text in a large number of PDF files? I would like to remove a URL that has been added to a set of files. I have been able to remove the link using javascript under Batch Processing in Adobe Pro, but the link text remains. I have seen recommendati…

How to list the properties of a JavaScript object?

Say I create an object thus: What is the best way to retrieve a list of the property names? i.e. I would like to end up with some variable ‘keys’ such that: Answer In modern browsers (IE9+, FF4+, Chrome5+, Opera12+, Safari5+) you can use the built in Object.keys method: The above has a full polyfi…

How do I unset an element in an array in javascript?

How do I remove the key ‘bar’ from an array foo so that ‘bar’ won’t show up in Answer Don’t use delete as it won’t remove an element from an array it will only set it as undefined, which will then not be reflected correctly in the length of the array. If you know the …

Easy way to turn JavaScript array into comma-separated list?

I have a one-dimensional array of strings in JavaScript that I’d like to turn into a comma-separated list. Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma-separated list? (I know how to iterate through the array and build the string myself by concatenation if tha…