0
array[i].trim();

is giving an error but only in ie8

it gives an error about 'unsupported method'.

Maybe .trim was removed in IE 9 ?

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

2 Answers2

1

String.trim() was added in 1.8.1 and was not implemented in IE8 or lower.

At the start of the code you can use

if(!String.prototype.trim) {
    String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/g,'');
    };
}

and .trim() will be implemented for any strings.

See here.

Snuffleupagus
  • 6,365
  • 3
  • 26
  • 36
0

Assuming array is an array of strings, the JavaScript String Object does not have a trim() method. See here.

Taken from this question you can do

array[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');

I hope that helps.

Community
  • 1
  • 1
RKumsher
  • 2,787
  • 2
  • 14
  • 11