tbody
у таблицы? Одна штука:document.querySelector('tbody').addEventListener('input', function() {
const data = Array.from(
this.children,
tr => Array.from(tr.querySelectorAll('input'), input => input.value)
);
console.log(data);
});
document.querySelector('table').addEventListener('input', e => {
const { map, flatMap } = Array.prototype;
const data = flatMap.call(
e.currentTarget.tBodies,
tbody => map.call(
tbody.rows,
tr => map.call(tr.cells, td => td.lastElementChild.value)
)
);
console.log(data);
});
// или
document.querySelector('table').addEventListener('input', function() {
const numHeadRows = this.querySelectorAll('thead tr').length;
const data = [];
for (const input of this.querySelectorAll('tbody input')) {
const td = input.parentNode;
const iCol = td.cellIndex;
const iRow = td.parentNode.rowIndex - numHeadRows;
(data[iRow] ??= [])[iCol] = input.value;
}
console.log(data);
});
const result = arr.reduceRight((acc, n) => ({ [n]: acc }), {});
let result = {};
for (let i = arr.length; i--;) {
result = { [arr[i]]: result };
}
const result = (function createObj(arr, i) {
return i < arr.length
? { [arr[i]]: createObj(arr, -~i) }
: {};
})(arr, 0);
const first = '125';
const startWithFirst = arr.filter(n => first.includes(`${n}`[0]));
console.log(startWithFirst);
const first = [ 1, 2, 5 ];
const startWithFirst = arr.filter(n => first.includes(n / (10 ** (Math.log10(n) | 0)) | 0));
const first = /^[125]/;
const startWithFirst = arr.filter(n => first.test(n));
const getSrc = img => img.getAttribute('src');
// или
const getSrc = img => img.attributes.src.value;
const relativeOnly = f => img => {
const src = getSrc(img);
if (!/^https?:\/\//.test(src)) {
f(img, src);
}
};
document.querySelectorAll('img').forEach(relativeOnly((img, src) =>
img.outerHTML = `
<picture>
<source srcset="${src}" type="image/svg+xml">
${img.outerHTML}
</picture>`
));
const wrapImages = relativeOnly((img, src) => {
const picture = document.createElement('picture');
const source = document.createElement('source');
source.srcset = src;
source.type = 'image/svg+xml';
img.replaceWith(picture);
picture.append(source, img);
});
for (const n of document.getElementsByTagName('img')) {
wrapImages(n);
}
// или
Array.prototype.forEach.call(document.images, wrapImages);
function makeRandomizer([ min, max ]) {
const numbers = [...Array(max - min + 1).keys()];
return () => numbers.length
? min + numbers.splice(Math.random() * numbers.length | 0, 1)[0]
: null;
}
function makeRandomizer([ min, max ]) {
const numbers = Array.from({ length: max - min + 1 }, (n, i) => min + i);
for (let i = numbers.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ numbers[i], numbers[j] ] = [ numbers[j], numbers[i] ];
}
return () => numbers.pop() ?? null;
}
const arr = Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.map(n => n[0]);
const arr = Object
.values(Object.entries(obj).reduce((acc, n) => ((acc[n[1]] ??= []).push(n[0]), acc), {}))
.reverse()
.flat();
package.json
, или .eslintrc.json
(все варианты тут). Так же и с prettier.