Search code examples
javascriptjqueryangularjsecmascript-6ecmascript-5

Convert ES6 arrow function to ES5 function JavaScript


What is the ES5 equivalent of the below code?

Object.keys($location.search()).forEach( key => ($location.search()[key] == null || $location.search()[key] == "") && $location.search([key], null));

I tried to replace the => with just a simple =, that resulted in a error however.

How do I convert the above code to the ES5 syntax.


Solution

  • You can either convert it into a function yourself or use something like Babel to do it for you

    Object.keys($location.search()).forEach(function (key) {
        return ($location.search()[key] == null || $location.search()[key] == "") && $location.search([key], null)
    });