| stripping a character away from a string JS |
circuitjump

msg:1489019 | 10:48 pm on Feb 15, 2002 (gmt 0) | Hi all, What would be the best way for me to go about strpping the last character in an array? For example: var Dimensional = [["0","0"],["1","1"],["2","2"],["3","3"],]; Whats the best way for me to get rid of that last commma? [add]In JavaScript that is.[/add] Thanks
|
wardbekker

msg:1489020 | 11:06 pm on Feb 15, 2002 (gmt 0) | I'm not sure if i understand the question correctly, but if you want to replace that last comma if you have a String like this; var Dimensional = '[["0","0"],["1","1"],["2","2"],["3","3"],]'; Then you could get rit of the last comma by using a regular expression re = /\]\,\]/gi; var newstr=str.replace(re, ']]');
|
circuitjump

msg:1489021 | 6:11 am on Feb 20, 2002 (gmt 0) | quick question. How does it exactly know to take off from the Dimensional Array?
|
wardbekker

msg:1489022 | 6:18 am on Feb 20, 2002 (gmt 0) | I'm very sorry, but i don't understand what you're saying. Please rephrase the question.
|
txbakers

msg:1489023 | 6:19 am on Feb 20, 2002 (gmt 0) | Hey there. In VB script it's as simple as this: dim harry as integer harry = len (proplist) proplist = left(proplist, harry - 1) but in Javascript it's a bitmore complicated. I would do it in VB script......
|
circuitjump

msg:1489024 | 6:33 am on Feb 20, 2002 (gmt 0) | Hi, My question is about the code you posted. The var newstr = str.replace(re, ']]'); I know I'm supposed to replace the str part with the variable name I'm trying to work with. But everytime I replace it to Dimensional.replace(re, ']]'); It ends up giving me an error. The error is : Object doesn't support this property or method. So I was just wondering if you can explain how to use the code a little more so that I can see if I'm doing something wrong. Oh, thanks txbakers, but I've been told to do it strictly in JS. :)
|
toadhall

msg:1489025 | 9:35 pm on Feb 20, 2002 (gmt 0) | I'll butt in:
var Dimensional = '[["0","0"],["1","1"],["2","2"],["3","3"],]';re = /\]\,\]/gi; var Dimensional=Dimensional.replace(re, ']]');
|
|
|