function replaceSubstring(phrase, words, replacement) {
words = words.split(' ');
let regExp = new RegExp(`\\b${words[0]}\\b(.*?)\\b${words[1]}\\b`);
return phrase.replace(regExp, `${words[0]} ${replacement} ${words[1]}`);
}
replaceSubstring('She is a robot', 'She robot', 'dreamed of a'); // 'She dreamed of a robot'
for (let i = 0; i <= 1;i++) { // вы перебираете первые две записи
if (new Date(response.data[i][1]).getDay() === 1) {
this.Monday = response.data; // и перезаписываете в нужный день ВСЮ выборку
}
}
this.daysData = new Array(7);
response.data.forEach(data => {
this.daysData[(new Date(data[1])).getDay()].push(data);
});
<div class="cityInfo" data-city="1">
<span class="cityInfo__city" data-city="1">1</span>
<span class="cityInfo__city" data-city="2">2</span>
</div>
<button class="cityToggler" data-city="1">toggle 1</button>
<button class="cityToggler" data-city="2">toggle 2</button>
.cityInfo .cityInfo__city { display: none; }
.cityInfo[data-city="1"] .cityInfo__city[data-city="1"] { display: block; }
.cityInfo[data-city="2"] .cityInfo__city[data-city="2"] { display: block; }
document.addEventListener('click', function (e) {
if (e.target.closest('.cityToggler')) {
document.querySelectorAll('.cityInfo').forEach(cityInfo => {
cityInfo.dataset.city = e.target.closest('.cityToggler').dataset.city;
});
}
});
<div class="car-selection" id="wrapper">
<p class="fleet" data-position="1050">луна</p>
<p class="fleet" data-position="2100">Солнце</p>
<p class="fleet" data-position="0">seas</p>
</div>
document.querySelectorAll('.fleet').forEach(fleet => {
fleet.addEventListener('click', function () {
sliderLine.style.left = -this.dataset.position + 'px';
});
});
$(this).closest('.t-item__inner').toggleClass('in');
let ids = [...document.querySelectorAll('#myTable tr')].map(x => x.id);
// или
let ids = $('#myTable tr').map(function () {return this.id;})).get();
function createSelectBrands(brands){
let select = document.createElement('select');
let html = '<option>Выбрать бренд из списка</option>';
brands.forEach(brand => {
html += `<option value="${brand.key}">${brand.name}</option>`;
});
select.innerHTML = html;
return select;
}