I have a function that I use to pass over a table field name and its value. Depending on the name of the field, it either returns the contents as a link or it does not.
// Given a field name, check to see if its in our output. If so, return the formatted link
function createLink(field, val) {
var output = {
'ntid': 'https://web.internal/profile/' + val,
'email': 'mailTo:' + val
};
var i, key, keys = Object.keys(output);
for ( i = 0; i < keys.length; ++i ) {
key = keys[i];
if(field.toLowerCase() == key){
return '<a href="'+output[key]+'" target="_blank">'+val+'</a>';
}
}
return val;
}
Usage:
createLink('email', '[email protected]')
// returns <a href="mailto:[email protected]">[email protected]</a>
This also works for NTID. The issue I am having though is there are some field names that contain my values in the output such as Sup Email or Sup NTID and those are not transformed correctly.
Expected Result:
createLink('sup email', '[email protected]')
// returns <a href="mailto:[email protected]">[email protected]</a>
The Question:
How can I tweak my function to see if my field exists in the output array at all, even if it's not an exact match?