Ребята, помогите одним махом (без циклов) заменить в строке все значения из массива. Вот подобный пример на php:
<?php
$string = "The quick brown fox jumped over the lazy dog.";
$patterns[0] = "/quick/";
$patterns[1] = "/brown/";
$patterns[2] = "/fox/";
$replacements[2] = "bear";
$replacements[1] = "black";
$replacements[0] = "slow";
echo preg_replace($patterns, $replacements, $string);
// The bear black slow jumped over the lazy dog.
?>
Мои попытки:
var patterns = new Array();
var replacements = new Array();
var string = 'The quick brown fox jumped over the lazy dog.';
patterns[0] = "quick";
patterns[1] = "brown";
patterns[2] = "fox";
replacements[2] = "bear";
replacements[1] = "black";
replacements[0] = "slow";
document.write(string.replace(new RegExp(patterns), replacements));