Verify only single value of one property in an array and matches criteria
Solution 1:
You can use Array#every()
and compare against the properties of the first element of the array.
const validate = (arr) =>
arr.every((a, _, [b]) => a.flag && (a.id === b.id || a.id === ''));
const arr1 = [{ id: '00001', flag: true }, { id: '00001', flag: true }, { id: '', flag: true },];
const arr2 = [{ id: '00001', flag: true, }, { id: '00002', flag: true, }, { id: '', flag: true, },];
const arr3 = [{ id: '00001', flag: true, }, { id: '00001', flag: false, }, { id: '', flag: true, },];
console.log(validate(arr1)); // true
console.log(validate(arr2)); // false
console.log(validate(arr3)); // false