0

I am pretty new in JavaScript development and I am finding some problem concatenating 2 strings.

So, I done:

alert(value);
var pagina = string.concat("edi.do?serv=3.C&ids=", value);
alert(pagina);

The alert(value) show me the aspected result that is something like: 68661-68662 but the second alert don't show the value of the pagina variable so I think that something is going wrong in the concatenation.

What am I missing? How can I fix this issue?

I need to obtain a string like: edi.do?serv=3.C&ids=68661-68662

Tnx

6 Answers 6

6

How about simply doing:

var pagina = "edi.do?serv=3.C&ids=" + value;
Sign up to request clarification or add additional context in comments.

1 Comment

Overkill is the term that came to my mind after seeing the question. This answer should have been accepted by now:)
2

var value = "68661-68662";
var pagina = "edi.do?serv=3.C&ids=" + value;
alert(pagina);

Comments

1

You are mixing up Java with JavaScript. Contact in javascript is done like this:

var pagina = "edi.do?serv=3.C&ids=" + value;

Comments

1

The problem is that "string.concat" is a null pointer, what is "string" in your context? The "string" variable should be the original string.

I guess what you are trying to achieve is:

var pagina = "edi.do?serv=3.C&ids=".concat(value);

You can also do as Marius suggested:

var pagina = "edi.do?serv=3.C&ids="+value;

Comments

1

To access string methods in JavaScript we use Object oriented design like this: "123".concat("456")

Also note that the class is represented by String, not string.

Comments

1

Although there are many acceptable answers here, I want to point out that one unmentionend method of concatenating strings in JavaScript is using Array's join() method:

var pagina = ["edi.do?serv=3.C&ids=", value].join();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.