homepage Welcome to WebmasterWorld Guest from 54.166.116.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
stripping a character away from a string
JS
circuitjump

10+ Year Member



 
Msg#: 47 posted 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

10+ Year Member



 
Msg#: 47 posted 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

10+ Year Member



 
Msg#: 47 posted 6:11 am on Feb 20, 2002 (gmt 0)

quick question.

How does it exactly know to take off from the Dimensional Array?

wardbekker

10+ Year Member



 
Msg#: 47 posted 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

WebmasterWorld Senior Member txbakers us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 47 posted 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

10+ Year Member



 
Msg#: 47 posted 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

10+ Year Member



 
Msg#: 47 posted 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, ']]');

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved