Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Check if property in each item of array is not null

Given the following object, how can I tell if all employees have a non null value for the SSN property?

Employees:
{ id: 0, name: "John", SSN: "1234" }
{ id: 1, name: "Mark", SSN: "1876" }
{ id: 2, name: "Sue", SSN: "98826" }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming that 0 is not a valid SSN, you can use Number(Employees[i].SSN) > 0 to make that determination:

TS Playground

const Employees = [
  { id: 0, name: "A", SSN: "1234"    }, // true
  { id: 1, name: "B", SSN: "1876"    }, // true
  { id: 2, name: "C", SSN: ""        }, // false
  { id: 3, name: "D", SSN: null      }, // false
  { id: 4, name: "E", SSN: undefined }, // false
  { id: 5, name: "F"                 }, // false
  { id: 6, name: "G", SSN: "98826"   }, // true
];

function hasSSN <T extends {SSN?: string | null | undefined}>(value: T): value is T & {SSN: string} {
  return Number(value.SSN) > 0;
}

for (const employee of Employees) {
  console.log(employee.name, hasSSN(employee));
}

Demo:

const Employees = [
    { id: 0, name: "A", SSN: "1234" },
    { id: 1, name: "B", SSN: "1876" },
    { id: 2, name: "C", SSN: "" },
    { id: 3, name: "D", SSN: null },
    { id: 4, name: "E", SSN: undefined },
    { id: 5, name: "F" },
    { id: 6, name: "G", SSN: "98826" }, // true
];
function hasSSN(value) {
    return Number(value.SSN) > 0;
}
for (const employee of Employees) {
    console.log(employee.name, hasSSN(employee));
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!