I am working on a function which looks through a list of table values on the page and if the column title contains any part of the output
, it will convert the value accordingly.
function createLink(field, val) {
var output = {
'ntid': 'https://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()).includes(key)) {
return '<a href="'+output[key]+'" target="_blank">'+val+'</a>';
}
}
return val;
}
The issue I am running into is that IE is throwing an error on the .includes()
line stating that "Object doesn't support property or method 'includes'".
I had a bit of trouble getting it to work as is but didn't realize includes()
must be something that not all browsers support.
Is there something else I can use in place of this that will allow for cross browser support ?
includes()
is part of the ES6
specification, so it's not supported in IE. What you can use instead is indexOf(element) !== -1
replace:
if(field.toLowerCase().includes(key)) {
to:
if(field.toLowerCase().indexOf(key) > -1) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With