Forum Moderators: open

Message Too Old, No Replies

Adding to a string

Ading to a string like PHP does with .=

         

bubblebug

4:01 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



I am quite new to javascript. I do all of the basic stuff ok but I have not written many custom functions.

I know a little PHP.

My question is how do I replicate PHP .= in javascript.

I have tried searching but I can not think of a phrase or term to search for as I do not know how to describe what I am trying to do in one or two words.

Basically I can start a string in PHP with:

$string = "something";

I can then add to it with:

$string .= "and some more";

Can you do that in javascriptm, if so how?

bubblebug

4:15 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



I rethought my logic and decided to add the string like this.

string = "something";

string = string + "something else";

This might not be right but it worked.

Anyone want to put me right, or is this the only way.
(I doubt it's the right way!)

ChadSEO

7:28 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



bubblebug,

The way to do this in JavaScript is using the += operator, like this:

string = "Hello";
string += " ";
string += "World";

Chad

bubblebug

7:54 am on Aug 23, 2005 (gmt 0)

10+ Year Member



Thanks,

It looks obvious to me now!