2

Please suggest me how to play with Join in javascript. My Code

var multiTokenQuery = value.join(',');
    submitted.set('multiTokenQuery', multiTokenQuery);

alert(multiTokenQuery);

the above code shows (abc,bcd) but I want it in ('abc','bcd') I mean I need single qoutes on the values ... Please Help

4
  • 1
    What is value? What do you need the apostrophes for? Commented Feb 20, 2014 at 11:31
  • 1
    Why do you need single quotes? What's the actual problem you're trying to solve? Commented Feb 20, 2014 at 11:31
  • @AnthonyGrist Please check my answer I have elaborated my problem ... Commented Feb 20, 2014 at 12:11
  • 1
    @user3332404: You better should edit your question instead of posting an answer… Commented Feb 20, 2014 at 12:53

2 Answers 2

1

Change the glue in the bits:

var multiTokenQuery = value != null && value.length > 0 ? "'" + value.join("','") + "'" : value;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Candide for your quick responce ..please chk my my post I have explained my problem hope you guys can suggest me something as I am new to java...
@user3332404 It seems you're new to Stack Overflow. I'd recommend you post your answer below, as another question. If you switch the context of your original question too much, well, everyone will have to revise their answers, and it's not nice for all involved.
1

You'd like to use the following instead to get your quotes.

var value = ['test','sample','example'];
var multiTokenQuery = "'" + value.join("','") + "'";

alert(multiTokenQuery);

JSFiddle: http://jsfiddle.net/FJUJ9/1/

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.