I need to combine all variables in one object:
$.get("https://www.virginmegastore.ae/en/gaming/playstation/playstation-games/sonic-forces---ps4/p/714792", function (data) {
var productNamePost=$("[name='productNamePost']").val();
var productCodePost=$("[name='productCodePost']").val();
var bg = $('.pdp_image-carousel-image.js-zoomImage-mobile').css('background-image');
var productPrice=$(".price__container > .price__value > .price__number").text();
var url = window.location.href;
console.log(url);
});
Sorry the question was unclear,i was need this
let obj = Object.assign({},var)
I also need to run the code when the button clicked
$.get("https://www.virginmegastore.ae/en/gaming/playstation/playstation-games/sonic-forces---ps4/p/714792", function (data) {
$("#addToCartForm > #addToCartButton").click(function(){
var productNamePost=$("[name='productNamePost']").val();
var productCodePost=$("[name='productCodePost']").val();
var bg = $('.pdp_image-carousel-image.js-zoomImage-mobile').css('background-image');
var productPrice=$(".price__container > .price__value > .price__number").text();
var url = window.location.href;
let obj = Object.assign({}, [productNamePost, productCodePost, bg, productPrice, url]);
console.log(obj)});
});
but i got below error when i clicked the button:
2
Answers
Try this:
This will create an object array with all your variables. Read more about
Object.assign()
hereLike this?