In operator returns true in a property not present in an object

45 views Asked by At

This is a snippet of code of code in QML Itme which is supposed to be using straight up JavaScript. However I cannot, for the life of me, figure out what is going on.

    let item =  itemList.get(vmCurrentIndex); // itemList is a ModelList
    console.log(JSON.stringify(item));
    console.log(("vmMetadata" in item));
    console.log(("vmIndex" in item));
    console.log(("vmText" in item));
    console.log(("hasMouse" in item));
    console.log(("something" in item));
    console.log(("or" in item));
    console.log(("other" in item));

The output of the tests above are:

qml: {"vmText":"No protocol","vmIndex":0,"hasMouse":false}
qml: true
qml: true
qml: true
qml: true
qml: true
qml: true
qml: true

Which makes no sense. only vmIndex, vmText and hasMouse are in item, everything else should have returned false. How is this possible? If I can't use the in operator how can I test if a key is present in a javascript object?

0

There are 0 answers