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]);
}
function createRandomArr(length, min, max) {
if (length > max - min + 1) {
throw 'такого массива быть не может';
}
const values = new Set;
for (; values.size < length; values.add(min + Math.random() * (max - min + 1) | 0)) ;
return [...values];
}
const createRandomArr = (length, min, max) => Array
.from({ length }, function() {
return this.splice(Math.random() * this.length | 0, 1);
}, Array.from({ length: max - min + 1 }, (n, i) => i + min))
.flat();
function createRandomArr(length, min, max) {
const arr = Array.from({ length: max - min + 1 }, (n, i) => min + i);
for (let i = arr.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ arr[i], arr[j] ] = [ arr[j], arr[i] ];
}
return arr.slice(0, length);
}