class Element {
constructor(el) {
this.el = el;
this.button = this.el.querySelector('[data-element-ref="button"]');
this.template = this.el.querySelector('[data-element-ref="template"]');
this.button.addEventListener('click', this.onClickPrimaryButton);
this.template.addEventListener('click', this.onClickButtonElement);
}
onClickPrimaryButton = () => {
this.template.innerHTML += template;
}
onClickButtonElement = (e) => {
if (e.target.dataset.elementRef === 'template-button') {
console.log(e.target);
}
}
}
const [ arr1, arr2 ] = arr.list
.map(n => [ n, +n.pos.dv.slice(1) ])
.sort((a, b) => a[1] - b[1])
.reduce((acc, n) => (acc[+(n[1] >= 38)].push(n[0]), acc), [ [], [] ])
.map(n => ({ list: n }));
const mustStay = arr => arr.every(n => n.value !== '-');
const newArr = arr.filter(mustStay);
arr.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), null);
// или
arr.splice(0, arr.length, ...arr.filter(mustStay));
// или
let numDeleted = 0;
for (const [ i, n ] of arr.entries()) {
arr[i - numDeleted] = n;
numDeleted += !mustStay(n);
}
arr.length -= numDeleted;
const DataList = ({ data }) => (
<div>
{data.map((item) => (
<div key={item.id}>
{item.title}
{item.round.map((r) => <div key={r.id}>{r.total}</div>)}
</div>
))}
</div>
);
<DataList data={props.data.slice(0, 3)} />
<Separator />
<DataList data={props.data.slice(3)} />
import { Fragment } from 'react'; // подключаем react fragment
....
// перед 3-им индексом, вставляем разделитель, индексы нумеруются от 0
render() {
return (
<div>
{
this.props.data.map((item, index) => {
console.log('item', item);
return (
<Fragment key={item.id}>
{index === 3 && (
<div>
разделитель
</div>
)}
<div key={item.id}>
{item.title}
{item.round.map((r) => {
console.log('r', r);
return (
<div key={r.id}>
{r.total}
</div>
)
})}
</div>
</Fragment>
)
})
}
</div>
)
}
const newArray = arr.reduce((result, elem) => {
const alreadyExist = Boolean(result.find(qwerty => qwerty.country === elem.country));
if(!alreadyExist) {
result.push({
id: result.length + 1,
country: elem.country
});
}
return result;
}, []);
const keys = [ 'firstName', 'lastName' ];
const values = document.querySelector('input').value.toLowerCase().match(/\S+/g) || [];
const result = arr.filter(n => keys.some(k => values.some(v => n[k].toLowerCase().includes(v))));
const baseURL = "https://www.website.ru/catalog/kurtki/?";
const data = {
size: [41332, 43296, 44278],
brand: [13974],
consists: [14, 2]
};
const resultURL = baseURL + "?" + encodeURIComponent(JSON.stringify(data));
const params = resultURL.split("?")[1];
const data = JSON.parse(decodeURIComponent(params));