[Solved] JS trim() function in cloudant


By definition, the trim() function will only remove leading and trailing white-space within a string, which may not be what you need in this scenario.

If you want to remove all white-space in general, you could consider using a Regular Expression replacement via the replace() function:

// This will remove all white-space from your input string
var output = input.replace(/\s/g,'');

After Your Update

Your code looks a bit more like you want to replace multiple instances of a space with a single space, which can still be done by a slightly different expression than the original :

// This replaces multiple repeated instances of a space with a single
var trimmedName = name.replace(/\s+/g,' ');
Index("default", trimmedName);

3

solved JS trim() function in cloudant