简体   繁体   中英

Iterate over map keys

I´m using kind of an object map on jQuery

  unitPerRestrictions[restriction]= product.quantity.numberOfUnits;

What I would like now is iterate over the keys to extract the values and use the key for other business logic. I cannot find a proper way to do this on jQuery Map and other implementations that I saw did not works

$.map(list, function(obj, index) {
    if(obj.prop2 == "yutu") {
        return index;
    }
})

You can use jQuery's each function.

var targetKey;
$.each(list, function(key, value) {
    if(value === "yutu") {
        targetKey = key;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM