How to change '(1,2,3,4)' to '1,2,3,4'

this is my code:

    var a='(1,2,3,4)'
    a=a.slice(-1,1)
    alert(a)

and I’m not printing anything.

thank

+3
source share
4 answers

I think you want to do:

a = a.slice(1, -1);
+9
source
a.substring(1,a.length-1)
1,2,3,4
+2
source

What about:

'(1,2,3,4)'.replace(/[()]/g, '')

Which will remove all (s) of the characters in the string, giving you:

"1,2,3,4"
+2
source

Another alternative:

var a='(1,2,3,4)';
a.replace(/^\((.*)\)$/, "$1");
0
source

Source: https://habr.com/ru/post/1739830/


All Articles