onlycode.org

javascript
jquery
html
angularjs
css
node.js
ajax
html5
php
json
arrays
google-chrome
dom
regex
reactjs
ecmascript-6
javascript-events

your's history:
programmatically constru...

Programmatically construct a condition for use in an if() statement, just only code

javascript

edit
var allOK = true;
for (var i = 1; i <= 100; i++) {
    if (!document.getElementById("div"+i).innerHTML) {
        allOK = false;
        break;
    }
}
if (allOK) {
    console.log("all my divs have content");
}
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
    console.log("all my divs have content");
}

29
Barmar, 09.12.2018 05:08




edit
var conditionResult = true;
for(var i = 1; conditionResult && (i < 101); i++) {
    conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}

if(conditionResult) {
    // Do something here
}
var arr = [/* array of DOM elements */];

var conditionResult = arr.every(elem => elem.innerHTML);   // This is equivalent to (innerHTML && innerHTML && ...)

var conditionResult = arr.some(elem => elem.innerHTML);    // This is equivalent to (innerHTML || innerHTML || ...)

28
ibrahim mahrir, 09.12.2018 05:07




edit
var conditional = true;
for(var i = 1; i <= 100; i++){
  if (!document.getElementById('div' + i).innerHTML) {
        condition = false;
        break;
    }
}

27
billynoah, 09.12.2018 05:10



edit
items.reduce((a, b) => a && b);

20
blue_note, 09.12.2018 13:21


edit
var conditionResult = true;
for(var i = 1; conditionResult && (i < 101); i  ) {
    conditionResult = conditionResult && document.getElementById('div'   i).innerHTML;
}

if(conditionResult) {
    // Do something here
}
var arr = [/* array of DOM elements */];

var conditionResult = arr.every(elem => elem.innerHTML);   // This is equivalent to (innerHTML && innerHTML && ...)

var conditionResult = arr.some(elem => elem.innerHTML);    // This is equivalent to (innerHTML || innerHTML || ...)

10
gdfdfgfdggfdfgsd, 12.04.2019 15:45


Add your just only code

your name:    



If you need full text click here

Some similar links Programmatically construct a condition for use in an if() statement ↓:
How to use OR condition in a JavaScript IF statement?

Assign variable in if condition statement, good practice or not?

What is the difference between if(!!condition) and if(condition)

execute statement after return statement in javascript



This project is created for those who just need only code, wihout maaaaaaaaaaany words.