ntzz
ntzz

Reputation: 183

Get data and make changes on javascript object

I have an object. But i don't know how to get the ID because it change for each page. So if make:

var obj = bundle.config.options

I get this result: https://i.sstatic.net/XHSPP.jpg

Then, i want to get in a var the number of the object -> '42' in this case

And then, i want to insert into the selection, and i hope it was like:

bundle.config.options[42].selections[314]

And then change the fields. Am i confused?

How could get this value?

UPDATE

I have associate by loop of other objets, the minQty of products for each product.

$minimumQty = $_selection->getStockItem()->getMinSaleQty();


                echo("<script>
                    var obj = bundle.config.options ;
                    var a = Object.keys(obj);

                    var keys = [];
                    for(var k in obj[a].selections) keys.push(k);


                    obj[a].selections[keys[d]].minQty = ".$minimumQty."
                      </script><br>");

The result -> each selection have the field: minQty with their number.

Upvotes: 2

Views: 57

Answers (1)

KAD
KAD

Reputation: 11102

Try using Object.keys(obj), here is a link on how it is used.

OR

You can loop through you Object and get the keys

var keys = [];
for(var k in obj) keys.push(k);

Upvotes: 1

Related Questions