1

I have this code:

var arr = "val=value1&val2=value2"; //coming from query string
 var [key, val] = arr.split('=');
 return "." + swapped[key.toLowerCase()][val.toLowerCase()];

however, I am having this error on the second line:

Expected identifier

I am having this issue on IE, it's working fine on chrome/firefox.

Any ideas?

I am doing maintenance for an existing site and they're having this issue on IE.

Edit

Here's the full code I have:

 url = decodeURI(url);
    var swapped = Object.keys(settings).reduce(function (obj, key) {
        obj[key.toLowerCase()] = Object.keys(settings[key]).reduce(function (obj2, key2) {
            obj2[settings[key][key2].toLowerCase()] = key2;
            return obj2;
        }, {});
        return obj;
    }, {});
    return url.toLowerCase().split(/[?&#]/).slice(1).map(function (arg) {
        var [key, val] = arg.split('=');
        return "." + swapped[key.toLowerCase()][val.toLowerCase()];
    });
9
  • IE doesn't support destructuring syntax. Commented Dec 22, 2016 at 0:02
  • What other syntax can I replace it with? I am not that familiar with JavaScript Commented Dec 22, 2016 at 0:02
  • var key = arr.split('=')[0]; var value = arr.split('=')[1]; Commented Dec 22, 2016 at 0:04
  • with [key, value], you assign value at 0 index to key and 1st index to value, assign them separately and it will work in ie too. Commented Dec 22, 2016 at 0:05
  • thanks @A.J, so the next line would like? how do I write it all together? Commented Dec 22, 2016 at 0:06

1 Answer 1

1

The code was written in ES6 as stated in comments, so I converted the code to ES5 using transpiler, and it worked.

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

Comments

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.