1

I have a javascript function that takes an object and remaps all of its key names to something else that I have defined.

Here is the function:

var nameMap = {
    SubmissionID: 'SubmissionID',
    MetaCreatedDate: 'Date',
    MetaCreatedDate_: 'MetaCreatedDate_',
    Program: 'Program',
    ViewedByInvestigator: 'Viewed',
    DateInvestigatorViewed: 'DateInvestigatorViewed',
    CaseID: 'CaseID',
    SecondaryReviewer: 'SecondaryReviewer',
    Investigator: 'Investigator',
    InvManager: 'Manager',
    InvSrManager: 'SrManager',
    WorkflowAction: 'WorkflowAction',
    Adjacency: 'Adjacency',
    Jurisdiction: 'Jurisdiction',
    Actions: 'Actions',
    Note: 'Note',
    recid: 'SubmissionID'
}

// Converted names
data = data.map(item => renameKeys(item, nameMap));

This function works great for Chrome/Firefox but I am having issues getting it to work in IE. I am receiving a syntax error on the line that is invoking the function.

Does IE not support mapping or is it written in a supported format? How can I account for this in IE?

SBB
  • 8,560
  • 30
  • 108
  • 223

1 Answers1

2

You are having this problem because IE11 does not support the Arrow function syntax. In the future, you can look at https://caniuse.com to determine if the JS functionality you are trying to use is supported in the browser you are testing. This is the link for the "fat arrow" function support.

// Your code that isn't working:
// data = data.map(item => renameKeys(item, nameMap));

// Functioning code for IE11:
data = data.map(function(item) {
  return renameKeys(item, nameMap);
});
th3n3wguy
  • 3,649
  • 2
  • 23
  • 30
  • +1 just learnt this now also .. Every day is a schoolday : Also for reference : https://learn.microsoft.com/en-us/scripting/javascript/reference/map-method-array-javascript – Pogrindis Mar 15 '18 at 14:30