0

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.

2
  • Missing function use function (key){ ...} Commented Jul 3, 2017 at 7:38
  • Ups, sorry. Added the missing =>. Thanks for noticing :) Commented Jul 3, 2017 at 7:39

3 Answers 3

3

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)
});
Sign up to request clarification or add additional context in comments.

1 Comment

I copied this code, and works among all browsers. Thanks!
2

To replace a arrow function you can´t just use a =, you need to use a regular function statement like:

(param) => {
  //code block 
}

function(param) {
  //code block
}

1 Comment

Thanks for the awnser and your time!
1

Just use an anonymous function (see documentation on forEach):

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

1 Comment

Thanks for the awnser and ur time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.