views:

111

answers:

4

this is my code:

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

and i print nothing.

thanks

+2  A: 
a.substring(1,a.length-1)
1,2,3,4
S.Mark
+9  A: 

I think you want to do:

a = a.slice(1, -1);
grapefrukt
And please see this also http://stackoverflow.com/questions/120804/difference-between-array-slice-and-array-slice
pramodc84
+2  A: 

What about :

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

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

"1,2,3,4"
Pascal MARTIN
@Pascal: don't you think a regex is a bit overkill for this sort of thing? For a more complex operation, regexes are fine, I just wonder about whether it's a good idea to encourage regexes where they are not needed.
Andy E
It might ^^ *(I'm one of those who says not to use regex too often -- should have said it in my answer)* ; but it was a possible solution that no-one proposed ; so I thought it couldn't hurt.
Pascal MARTIN
@Pascal: well, it is good to have a few alternatives :-)
Andy E
A: 

Another alternative:

var a='(1,2,3,4)';
a.replace(/^\((.*)\)$/, "$1");
Álvaro G. Vicario