const arr = [
{src: 'some-path-1', video: 'some-path-1'},
{src: 'some-path-2', video: 'some-path-2'},
{src: 'some-path', video: null},
];
const result = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i]?.video) {
result.push({ src_video: arr[i].video });
}
result.push(arr[i]);
}
console.log(result);
const result = arr.reduce(
(acc, cur) => {
if (cur.video !== undefined) {
acc.push({ src_video: cur.video });
}
acc.push(cur);
return acc;
},
[],
)
// Array(5) [ {…}, {…}, {…}, {…}, {…} ]
// 0: Object { src_video: "some-path-1" }
// 1: Object { src: "some-path-1", video: "some-path-1" }
// 2: Object { src_video: "some-path-2" }
// 3: Object { src: "some-path-2", video: "some-path-2" }
// 4: Object { src: "some-path", video: null }
const links = [
'mysite.com/param/sometext-alt-text/otherparam/text?zzzz',
'mysite.com/param/foo/otherparam/qqqqqq',
'mysite.com/param/123/otherparam/jfghjfghk?...',
'mysite.com/param/foo/otherparam/gdfsghdfhkj',
'mysite.com/param1/sometext-alt-text/otherparam/text?zzzz',
'mysite.com/param2/foo/otherparam/qqqqqq',
'mysite.com/param/123/otherparam3/jfghjfghk?...',
'mysite.com/param/foo/otherparam4/gdfsghdfhkj',
];
const re = /param\/(?<param>.+)\/otherparam\/(?<otherparam>.*)/;
links.forEach(link => {
const found = link.match(re);
console.log(link, found);
});
href
.Infinity
списал у 0xD34F const sorted = arr
.map(n => [
n,
+new URLSearchParams(n.querySelector('a').href.split('?').pop()).get('value') || Infinity,
])
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
parentEl.append(...Array
.from(parentEl.querySelectorAll('a'), n => [
n.parentNode,
Number(n.getAttribute('href').match(/(?<=value=)\d+/)) || Infinity,
])
.sort((a, b) => a[1] - b[1])
.map(n => n[0])
);
<li className={someCondition ? someClass : someOtherClass} />
someProp === SOME_CONSTRANT
<li className={getClassName(someProp)} />
key = {this.props.data[index]['id']}
key = {value.id}