0

I have an object as below,

var types = {
    '1': 'Trading Status: Active              '
}

How can I remove that extra white space after my value of that object?

I have tried the trim white space setting. But it didn't work. How can I do it?

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
chewi
  • 159
  • 2
  • 3
  • 16
  • 1
    You want to know how to do it with javascript or with a configuration option of visual studio? Just to clarify your needs... – Shidersz Feb 19 '19 at 03:38
  • 1
    Configuration of VS code – chewi Feb 19 '19 at 03:55
  • 1
    @Sajeetharan: I dont know why you marked it as duplicate when i clearly said trim white space did not fixed this issue? Are you that sure its the fix? – chewi Feb 19 '19 at 03:56
  • @chewi press `F1` and then type `Format Document` and `ENTER` will format your code with removing spaces and fixes indentation. – AlokeT Feb 19 '19 at 05:02
  • Hi, tried but didnt work – chewi Feb 19 '19 at 09:55
  • Yes, it is ***not a duplicate*** of that question. That question is for the general text editor feature of removing trailing white space. ***This question*** is much more specialised (programming language specific), removing space inside character strings. Note that it is ***tagged with JavaScript***. – Peter Mortensen Mar 22 '20 at 19:42
  • it is also **tagged as visual-studio**, and titled as **Visual-Studio**, and when asked he specified that he wants this as **Configuration of VS code**, not javascript `trim()`. That said, it is still unclear what the OP is looking for. – SherylHohman Mar 23 '20 at 07:45
  • If you want a javascript solution, try: `types['1'] = types['1'].trim();`. – SherylHohman Mar 23 '20 at 07:50
  • I think OP does not understand what trimming whitespace in the editor is vs whitespace within a string in the code. Trimming trailing whitespace in the editor removes invisible whitespace that is NOT part of the code itself. This doesn't affect the program, but will affect "diffs" if the whitespace changes. If that does not make sense to you, don't worry about it. The code you included in your question is whitespace *within js code*. That is part of the string. Visual Studio configuration cannot touch that. You would need to either delete that whitespace manually, or use the `trim()` function. – SherylHohman Mar 23 '20 at 08:03
  • Here is the duplicate for javascript `trim()`: https://stackoverflow.com/questions/196925/what-is-the-best-way-to-trim-in-javascript. You can try it out here: https://www.w3schools.com/jsref/jsref_trim_string.asp. Here is a repl showing the results with your example: https://repl.it/@sherylhohman/GigaEnchantedArguments – SherylHohman Mar 23 '20 at 08:07
  • @SherylHohman: It could be about manipulation of source code by the IDE, e.g. like built-in functions (or by means of plugins) for refactoring would manipulate the source code. The OP said, when asked, *"Configuration of Visual Studio Code"*. – Peter Mortensen Mar 24 '20 at 23:38
  • It is rather **unclear exactly what the OP is asking**. And it seems to be a dead post, as OP does not respond or clarify. There might be a mix-up in terminology used to ask his question. He may be looking for some plugin that could manipulate strings or as, Mortensen suggested, to reformat? If he's looking for javascript is it definitely a duplicate. If he is looking for a Visual Studio built-in solution (for trimming code white space, as opposed to whitespace within strings), well, this question was previously closed as a duplicate for *that* interpretation of the Q, & he said it didn't work – SherylHohman Mar 25 '20 at 00:21

1 Answers1

0

var types = {
    '1': 'Trading Status: Active              '
}
// Remove the extra space
console.log(types['1'].trim())

// You can check it there is no more space by the length

console.log(types['1'].trim().length)
RedJanvier
  • 95
  • 4
  • I think that method of String types trim() might solve your issue but let me know if it did help or not – RedJanvier Mar 23 '20 at 12:11
  • Actually I think VSCode can't help with that issue because it considers the extra space to be part of a string value and It won't change the value of your variables. With that said I think if you still want to remove the extra space you can use the JS method. – RedJanvier Mar 23 '20 at 13:42