[Solved] In JavaScript, what is the simplest way to insert text into a string?


Use:

var queryStringParts = queryString.split('&');
var pairs = queryStringParts.map(function(str) { return str.split('=') })
var rewrittenParts = pairs.map(function(pair){
                          return 'slides[0].' + pair[0] + '=' + pair[1]
                     });
var newQuerystring = rewrittenParts.join('&');

As was pointed out in the comments, in this specific case we could skip the split into pairs step and just do

var queryStringParts = queryString.split('&');
var rewrittenParts = queryStringParts.map(function(part) {
                          return 'slides[0].' + part
                     });
var newQuerystring = rewrittenParts.join('&');

6

solved In JavaScript, what is the simplest way to insert text into a string?