const obj = arr.reduce((result, item) => {
const [key, value] = item.split('=');
if (!result[key]) {
result[key] = [];
}
result[key].push(value);
return result;
}, {})
{
utmTerm: ['java', 'javascript', 'swift'],
}
correct_date = `${hour}:${min}`;
// correct_date = `${hour}:${min}:${sec}`;
const getTimeString = () => {
const subbed = new Date();
const hour = subbed.getHours().toString().padStart(2, '0');
cosnt min = subbed.getMinutes().toString().padStart(2, '0');
const sec = subbed.getSeconds().toString().padStart(2, '0');
return `${hour}:${min}:${sec}`;
}
let clock = document.getElementById('clock')
setInterval(() => {
clock.innerHTML = getTimeString();
}, 1000);
if ($(this).find('input[name="DATA[NAME]"]').val().length < 2 ) {
return (alert("Введите имя"), !1)
} else if (0 == IsEmail(t)) {
return (alert("Введите корректный email"), !1)
} else {
return ($.ajax({...тут отправка формы})
}
const array = ['я в Симбирск,', 'в трактире.', '...']
const order = [3, 7, 0, 8, 11, 5, 9, 6, 4, 1, 12, 2, 10]
const strings = order.reduce((strings, number) => [...strings, array[number]], [])
const result = strings.join(' ')
function debounce(f, ms) {
let isRunning = false;
return function() {
if (isRunning) return;
f.apply(this, arguments);
isRunning = true;
setTimeout(() => isRunning = false, ms);
};
}
function myFunction {
console.log('i am working');
}
const debouncedMyFunction = debounce(myFunction, 2000);
debouncedMyFunction(); // Выполнится
debouncedMyFunction(); // Будет проигнорирована
this.array.splice(oldElementIndex, 1, newElement)
this.$set(this.array, oldElementIndex, newElement)
this.array = this.array.map(el => {
el.someParam = 1
return el
})
const copyOfArray = JSON.parse(JSON.stringify(sourceArray))
const f = (arr = []) => {
arr.push(1)
arr.push(2)
return arr
}
const basicArr = f([]) // [1,2]
f(basicArr)
console.log(basicArr) // [1, 2, 1, 2]
data()
data: () => ({ param: 1 }) //Возвращает объект
data: () => {
return {
param: 1
}
}
const obj = { a: 100, b: 152, c: { y: 133, x: { m: 20} } }
const flatObject = (current) => {
return Object.keys(current).reduce((acc, cur) => {
if (typeof(current[cur]) !== 'object') {
acc[cur] = current[cur]
} else {
acc = {...acc, ...flatObject(current[cur]) }
}
return acc
}, {})
}
console.log(flatObject(obj))
async function getChannel(urlChannel){
const urlChannelResult = await fetch(urlChannel)
const jsonChannel = await urlChannelResult.json()
const authorPhoto = jsonChannel.items[0].snippet.thumbnails.high.url
console.log(authorPhoto
return authorPhoto
}
[...].map(async el => {
const authorPhoto = await getChannel(el.url)
// ....
})