true if all properties pass the check, false otherwise
const config = { timeout: 5000, retries: 3, enabled: true };
const allValid = allKeysValid(config, (value, key) => {
if (key === 'timeout') return typeof value === 'number' && value > 0;
if (key === 'retries') return typeof value === 'number' && value >= 0;
if (key === 'enabled') return typeof value === 'boolean';
return true;
}); // true
const scores = { alice: 95, bob: 87, charlie: 92 };
const allPassed = allKeysValid(scores, (score) => score >= 90); // false (bob: 87)
// Validate form data
const formData = { name: 'John', email: '[email protected]', age: 30 };
const isValid = allKeysValid(formData, (value, field) => {
return value !== null && value !== undefined && value !== '';
});
Performs a for-in loop that breaks when the check function returns false.
Iterates over object properties (including inherited enumerable properties) and stops early if the check function returns false for any property.