Не могу понять как правильно написать цикл перебора.
$('.hello').attr('data-class', function() {
return [...this.classList].filter(n => n !== 'hello');
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.replace(/(^| )hello( | $)/, ' ').trim();
});
$('.hello').attr('data-class', function() {
return this.classList[1];
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.split(' ').pop();
});
Array.prototype.push.apply(
arr,
newArr.filter(n => !arr.some(m => m.trade_id === n.trade_id))
);
const pushDiff = (target, source, key = n => n) =>
target.push(...source.filter(function(n) {
return !this.has(key(n));
}, new Set(target.map(key))));
pushDiff(arr, newArr, n => n.trade_id);
Пробовал через массивы, но не работает.
['negative', '', 'positive'][Math.sign(article.total_comments.length) + 1]
import Vue from 'vue/dist/vue.esm.js'
import Vue from 'vue'
.row {
counter-reset: list -1;
}
.row a::before {
content: counter(list);
counter-increment: list;
}
.row a:first-child::before,
.row a:last-child::before {
content: "";
}
.row {
counter-reset: list 0;
}
.row a:not(:first-child, :last-child)::before {
content: counter(list);
counter-increment: list;
}
const inputSelector = '#kmOutMKAD';
const radioSelector = '[name="delivery"]';
const disabledValue = '1';
$(radioSelector).on('change', function() {
$(inputSelector).prop('disabled', this.value === disabledValue);
});
// или
const input = document.querySelector(inputSelector);
const radios = document.querySelectorAll(radioSelector);
const onChange = e => input.disabled = e.target.value === disabledValue;
radios.forEach(n => n.addEventListener('change', onChange));
$scope.edit = function(index) {
$scope.active = index;
};
ng-disabled="$index !== active"
overlay.addEventListener('click', function(e) {
if ([ '#close-menu', 'li > a' ].some(n => e.target.matches(n))) {
overlay.classList.remove('show-menu');
}
});
const
text = 'Sport',
str = 'port';
console.log(text.replace(new RegExp(`(${str})`, 'g'), '#$1#'));
или есть что-то оптимальней ?
text.replace(str, `#${str}#`)
. Правда, в отличие от регулярки - множественную замену так сделать не получится.