View on GitHub

array-polyfills

This is an array polyfill , one .js file for support some array methods (map, filter, reverse, forEach etc.) which maybe doesn't support in old browser or anyone can learn how to create custom array methods from this repository.

array-polyfills

What is Polyfills?

Javascript polyfills are the javascript codes which are written to support unsupported javascript features.

what is array-polyfills?

This is javascript codes which are written to support few array methods(example: map, filter, forEach, reverse etc.) for those browsers which doesn’t support these methods. Along with that anyone can learn how to create polyfill or custom array methods.

Prerequisites

All array polyfills are written in index.js file of main branch of this repository. Anyone have to add this file before of any js files or js codes of your application. For example if anyone want to use in their application and if their root file of their application is index.html

Code of Array map polyfil

  if (!Array.prototype.map) {
    Array.prototype.map = function(callback){
      var arr = [];
      try {
        for(var i = 0; i<this.length; i++) {
          arr.push(callback(this[i]));
        }
      }catch(e){
        throw new Error(e);
      }
      return arr;
    }
  }
  var arr = [1,2,3];
  var newArr = arr.map((item) => item + 1);
  console.log(newArr); // [2,3,4]

Supported Array methods