user3332404
user3332404

Reputation: 171

Join syntax in javascript

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

Upvotes: 2

Views: 113

Answers (2)

Petr Vostrel
Petr Vostrel

Reputation: 2332

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/

Upvotes: 1

Roland Mai
Roland Mai

Reputation: 31077

Change the glue in the bits:

var multiTokenQuery = value != null && value.length > 0 ? "'" + value.join("','") + "'" : value;

Upvotes: 1

Related Questions