The past few weeks were dedicated to the useful array methods. However these methods have been implemented in ECMAScript 5 and are therefore not available in older browsers such as IE8 and sometimes we have to support legacy browsers.
Basically what happens is that we first do a feature detection. Is the feature available in the browser? For example, does Array.prototype.map exist? Yes? That’s great! It means the feature has been implemented and is probably faster than every polyfill that we could come up with. Is it not available? Too bad, but we can create the Array.prototype.map method ourselves.
The Mozilla Developer Network has some of the most robust polyfills that are still fast in use. It also has an excellent documentation about the array methods. Here’s the page for the map functionality.
Using a polyfill doesn’t change the way the method is being called. If your browser does not support the map-method and you use a polyfill, you will still use it like this: [1, 2, 3].map(…); This is useful, because you don’t have to change syntax for different browsers.
Another solution is to use a framework that has implemented these functionalities. One of my favourites is underscore. This framework adds more useful methods than just the array methods to your function toolbelt.
framework adds more useful methods than just the array methods to your function toolbelt.