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

199
Views
Difference between not initialized and undefined value
let a = Array(3);
a[0] = 1;
a[1] = undefined;

function test(arr) {
  return arr.map(a => !!a);
}

console.log('before', a); // [1, undefined, undefined]
console.log('after', test(a)); // [true, false, undefined]

How can I check if array element is initialized as undefined (a[1]) or not initialized (a[2])? a[2] has empty value, but browser converts it to undefined.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use hasOwnProperty with the index.
When no value at the index is set, hasOwnProperty returns false:

const a = Array(3);
a[1] = undefined;

console.log(a.hasOwnProperty(0));
console.log(a.hasOwnProperty(1));
console.log(a.hasOwnProperty(2));

in works as well:

const a = Array(3);
a[1] = undefined;

console.log(0 in a);
console.log(1 in a);
console.log(2 in a);

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!