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

135
Views
Why the output of this is number instead of items in array?

My intention is is to get an array of arrays. i.e [['item','C']]. I'm unable to figure out why the below code always produces [2] ? Could someone please help?

function arrayOfArrays() 
{
 return [].concat([].push('item','C'))
}

console.log(arrayOfArrays());

console.log(arrayOfArrays());

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

0

Array#push returns:

The new length property of the object upon which the method was called.

Whereas, Array#concat returns:

A new Array instance.

Try this instead:

console.log( [[].concat('item','C')] );
// OR
console.log( [ ['item','C'] ] );

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!