TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why never use new Array in Javascript

1 pointsby Parsecoover 12 years ago
I love Javascript, but sometimes it seems it doesn't love me back. Take for instance the Array constructor function...

2 comments

bdfh42over 12 years ago
I agree that var a = new Array(1,2,3,4,5); is an old construct and should be replaced by var a = [1,2,3,4,5];<p>but the form<p>var a = new Array(10);<p>can be very effective when you need an array with n elements and you are not in a position to .push() new ones in - you just need those elements to be there.<p>No confusion here - just lots of helpful language features.
dragonbonheurover 12 years ago
Those arrays are behaving exactly how arrays behave in any language. Can't see the problem here.