JavaScript : for (let item of items)


#1

I’m new to JavaScript and I have tried to modify findBestItem(items) in level “Diamond Dozen” using for and while loops.

    while(i < items.length) {    // some code
    }

and

    for(var i=0; i < items .length; i++) { // some code
    }

passe without problems. But I can not understand how and which of constructions " for…of" I can use for iterating coins, enemies… ( documentation: for…of). Not so successful attempt with

for (let item of items)

function findBestTresure(items) {
    var bestItem = null;
    var item = null;
    var bestValue = 0;
    var ratio = 0;
    for (let item of items) {
        ratio = item.value / hero.distanceTo(item);
        if( ratio > bestValue) {
            bestItem = item;
            bestValue = ratio;
        }
    }    
    return bestItem;
}