var cart = {};
function addToCart() {
var articul = this.dataset.id;
cart[articul] = 1;
console.log(cart);
}
document.getElementById('addToCart').addEventListener('click', addToCart);
var swiper;
function resizeScrenn() {
if ($(window).width() >= 1200) {
if ($("#swiper-container").length > 0) {
swiper = new Swiper('#swiper-container', {
direction: 'vertical', // вертикальный слайдер
slidesPerView: 1,
spaceBetween: 0,
loop: false,
touchRatio: 0,
slidesPerGroup: 1,
});
}
} else {
swiper.destroy(); // или swiper.autoplay.stop();
}
}
resizeScrenn();
$(window).resize(function () {
resizeScrenn();
});
const path = 'dir1/dir2/dir3/dir4/';
const pathArray = path
.replace(/\/$/g, '')
.split('/')
.map((dir, index, paths) => {
return {
key: dir,
path:
paths.slice(0, index).join('/') +
`${index !== 0 ? '/' : ''}${dir}/`
};
});
console.log(pathArray);
var regexp = new RegExp(/&&-img_1-&&/g);
console.log('&&-img_1-&&'.replace(regexp, 'img'));
var myNumber = 2;
var myVar = '&&-img_' + myNumber + '-&&';
var regexp = new RegExp(myVar, 'g');
console.log('&&-img_2-&&'.replace(regexp, 'img'));
var regexp = new RegExp(/&&-img_\d-&&/g);
var keys = ['key1', 'key2', 'key3'];
var values = ['val1', 'val2', 'val3'];
var keyValObj = {};
key.forEach(function(item, index) {
keyValObj[item] = values[index];
});
console.log(keyValObj);