Javascript If List Cotains?

<>

This question already has an answer here:

Answers


If chatBoxes is an object, you need to use the flag to findout whether the object contains the said value, then after the loop you need to do the action which is depending on the contains flag.

var contains = false;
for (x in chatBoxes) {
    if (chatBoxes[x] == obj[i].from) {
        contains = true;
        break;
    }
};

if (contains) {
    alert(obj[i].from + " YES !");
} else {
    alert(obj[i].from + " NOPE !");
}

But if chatBoxes is an array

if(chatBoxes.indexOf(obj[i].from) > -1){
    alert(obj[i].from + " YES !");
} else {
    alert(obj[i].from + " NOPE !");
}

Assuming chatBoxes is an array, use indexOf()

if (chatBoxes.indexOf(obj[ i ].from) > -1)

Need Your Help

Bind modified in runtime viewmodel

javascript mvvm knockout.js

I've faced problem with binding modified at runtime viewmodel through prototype to particular html elements.

Does Monitoring An Excel Spreadsheet Via RDP Make It Slower?

excel vba remote-desktop cpu-usage

We have a massive spreadsheet which does a lot of calculations and not much drawing / writing to spreadsheets