function scrollTracking(entries) {}
const observer = new IntersectionObserver(scrollTracking, {
threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
});
observer.observe(YOUR_ELEMENT));
text
у какого-то значения. Например:record.messages[0]['item_apply_id'].text
record.messages[1]['add_date'].text
for (let i = 0; i < record.messages.length; i++) {
for (let message in record.messages[i]) {
console.log(i, message, record.messages[i][message]);
}
}
0 "id" "2222"
0 "item_apply_id" "693575"
0 "text" "aaaaaa"
0 "uid" "283238"
0 "add_date" "2020-07-20 19:19:12"
text
каждого элемента, следует использовать такой цикл:for (let i = 0; i < record.messages.length; i++) {
console.log(record.messages[i].text);
}
const deleteHandler = function (array) {
const filtered = array.filter(entry => entry !== this);
array.length = 0;
array.push(...filtered);
};
const array = [
{
id: 1,
delete: deleteHandler,
},
{
id: 2,
delete: deleteHandler,
},
];
console.log(array); // [ { id: 1, delete: [Function: deleteHandler] }, { id: 2, delete: [Function: deleteHandler] } ]
const a = array[1];
a.delete(array);
console.log(array); // [ { id: 1, delete: [Function: deleteHandler] } ]
Map
, вместо такого поведения. <iframe>
).const getPage = async url => {
const request = new Request(url, {
method: 'GET',
headers: new Headers({ 'Content-Type': 'text/html; charset=utf-8' }),
});
const response = await fetch(request);
const text = await response.text();
const parser = new DOMParser();
const virtualDocument = parser.parseFromString(text, 'text/html');
return virtualDocument;
};
getPage('some.html').then(virtualDocument => {
document.querySelector('.result').append(...virtualDocument.body.children);
});
$(document).ready(function () {
$('select').change(function () {
const id = $(this).val();
const target = $(`#${id}`);
if (target.length !== 0) {
$('html, body').animate({
scrollTop: target.offset().top
}, 250);
}
});
});
const select = document.querySelector('select');
select.addEventListener('change', event => {
const target = document.getElementById(event.target.value);
if (target !== null) {
target.scrollIntoView({
behavior: 'smooth'
});
}
});
const items = [
{
name: 'Apple',
dropChance: 0.7
},
{
name: 'Knife',
dropChance: 0.25
},
{
name: 'Spoon',
dropChance: 0.25
},
{
name: 'Ice Cream',
dropChance: 0.1
}
];
const lerp = (min, max, value) => ((1 - value) * min + value * max);
const drop = items => {
const total = items.reduce((accumulator, item) => (accumulator + item.dropChance), 0);
const chance = lerp(0, total, Math.random());
let current = 0;
for (const item of items) {
if (current <= chance && chance < current + item.dropChance) {
return item;
}
current += item.dropChance;
}
};
const removeNonUnique = array => {
const cache = new Set();
const store = new Set();
for (const entry of array) {
if (cache.has(entry)) {
store.delete(entry);
} else {
cache.add(entry);
store.add(entry);
}
}
return [...store];
};
console.log(
removeNonUnique([1, 2, 1, 1, 42, 3, 1, 3, 2, 3])
);