Hi I need help with the method that follows: var ages = [3, 10, 18, 20];
function checkAdult(age) { return age >= 18; }
function myFunction() { document.getElementById("demo").innerHTML = ages.findIndex(checkAdult); }
Hi I need help with the method that follows: var ages = [3, 10, 18, 20];
function checkAdult(age) { return age >= 18; }
function myFunction() { document.getElementById("demo").innerHTML = ages.findIndex(checkAdult); }
It's entirely possible that the values are null instead of an empty string. There is a difference between the two (JavaScript actually has both null and undefined types that represent a missing a value). Also, findIndex is not necessary here, you can just use find:
const test = !!data.find(value => value.Fname || value.Lname);
The !! notation converts a falsy value to false and a truthy value to true without a ternary operator. A value is falsy if it is null, undefined, empty string, 0, or false, and true otherwise. This should be sufficient for your use case.
Also, I noticed a typo in your code, which I've fixed, above. Lanme is probably meant to be Lname. Pay attention to typos, as that can easily cause hard-to-detect problems in JavaScript.
undefined, not ''.