const arr = Array.from(
new Set(Array.from(document.querySelectorAll('.shop_name'), n => n.innerText)),
n => ({ name: n })
);
const arr = Object.values(Array.prototype.reduce.call(
document.getElementsByClassName('shop_name'),
(acc, { textContent: name }) => (acc[name] ??= { name }, acc),
{}
));
success: function(response){
setTimeout(function() {
document.location.href = `site.ru/test.php?number=${response.number}&name=${response.name}`;
}, 2000);
}
success: function(response){
localStorage.setItem('some_key', JSON.stringify(response.data));
setTimeout(function() {
document.location.href = 'site.ru/test.php';
}, 2000);
}
let helloHabr = JSON.parse(localStorage.getItem('some_key'));
function shortNumber(val) {
const abs = Math.abs(val);
const prefixIndex = Math.log10(abs) / 3 | 0;
return (
(val < 0 ? '-' : '') +
Math.round(abs / (10 ** (prefixIndex * 3))) +
'KMGTPEZY'.charAt(~-prefixIndex)
);
}
shortNumber(99) // '99'
shortNumber(1945) // '2K'
shortNumber(-5839465) // '-6M'
shortNumber(7e10) // '70G'
[].toString() + true + false - null
"" + true // "true"
"" + true + false // "truefalse"
"" + true + false - null // NaN
+
не строка, то это не конкатенация и true, false, null будут преобразованы к числам.true + false - null + [].toString()
1 + 0 // 1
1 + 0 - 0 // 1
1 + 0 - 0 + "" // "1"
document.querySelectorAll('.slider__itm img').forEach(n => {
const link = document.createElement('a');
n.parentNode.append(link);
link.append(n);
});
for (const n of document.querySelectorAll('.slider__itm')) {
n.innerHTML = `<a>${n.innerHTML}</a>`;
}
for (const n of document.getElementsByClassName('slider__itm')) {
const link = document.createElement('a');
link.appendChild(n.replaceChild(link, n.children[0]));
}
const imgs = document.querySelectorAll('.slider__itm img');
for (let i = 0; i < imgs.length; i++) {
const link = document.createElement('a');
imgs[i].replaceWith(link);
link.insertAdjacentElement('afterbegin', imgs[i]);
}