0

I want to add "*." at opening and ";" at ending on each array element. Below is the sample code.

var ext = getExt(filename);
var s = '<%=AllowedExtensions %>';
var match = s.split(', ');

In the above code in 'match' I use to get ["jpg", "png", "txt"] like this. So here on each array element I want to prefix with "." and at end of each want to add ";" and also it should give me a string such as ".jpg;.png;.txt;" .

3 Answers 3

1

Try this:

var matchString = '.' + match.join(';.') + ';'
Sign up to request clarification or add additional context in comments.

Comments

1

ES5 code:

match = match.map(function( word ) {
    return '*.' + word + ';';
}).join('');

ES3 code:

for(var i = 0, len = match.length; i < len; i++) {
    match[ i ] = '*.' + match[ i ] + ';';
}

match = match.join('');

Demo: http://jsfiddle.net/PNDr6/1/

Comments

0

You can do something like this:

for(var k = 0; k < match.length; k++)
{
    match[k] = '*.' + match[k];
}
var allExten = match.join(';');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.