2

I have the following bit of code which adjusts the headers of some parsed data:

    var parsedData = transposed.map(row =>
        row.reduce((acc, col, ind) => {
            acc[headers[ind]] = col;
            return acc;
        }, { }));

The code works fine on Chrome/Edge/Firefox but fails on Internet Explorer saying there's a syntax error at: row =>.

I'm unable to determine where the syntax error is being thrown - I'm relatively new to javascript's map function so I may be missing something. Where in the above code snippet is the syntax error?

2 Answers 2

10

Arrow functions are a core part of the ES6 language feature set.

Those are not directly supported in IE, you need to transpile your code first.

Babel is the go-to transpiler for ES6.

Sign up to request clarification or add additional context in comments.

Comments

3

IE is old and does not understand the arrow function syntax.

reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions

you might need to use the old anonymous function to make it compatible with IE or if polyfill exists, use those. or use transpilers (such as Babel) to transpile it to es5.

example of old annonymous function:

transposed.map(function(row){
        row.reduce((acc, col, ind) => {
            acc[headers[ind]] = col;
            return acc;
   }, { });
});

but remember, you will lose scope of the outside this

1 Comment

Also, there's two arrow functions in OP's example, you only translated the outer one :)

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.