Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning JavaScript Data Structures and Algorithms

You're reading from   Learning JavaScript Data Structures and Algorithms Enhance your problem-solving skills in JavaScript and TypeScript

Arrow left icon
Product type Paperback
Published in Sep 2026
Publisher Packt
ISBN-13 9781836205395
Length 615 pages
Edition 4th Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Loiane Groner Loiane Groner
Author Profile Icon Loiane Groner
Loiane Groner
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Learning JavaScript Data Structures and Algorithms, Fourth Edition: Enhance your problem-solving skills in JavaScript and TypeScript
1 Introducing Data Structures and Algorithms in JavaScript FREE CHAPTER 2 Big O notation 3 Arrays 4 Stacks 5 Queues and Deques 6 Linked Lists 7 Sets 8 Dictionaries and Hashes

Creating and initializing arrays

Declaring, creating, and initializing an array in JavaScript is straightforward, as shown in the following example:

let daysOfWeek = new Array(); / {1}
daysOfWeek = new Array(7); / {2}
daysOfWeek = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); / {3}
/ preferred
daysOfWeek = []; / {4}
daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; / {5}

We can:

  • Line {1}: declare and instantiate a new array using the keyword new – this will create an empty array.
  • Line {2}: create an empty array specifying the length of the array (how many elements we are planning to store in the array).
  • Line {3}: create and initialize the array, passing the elements directly in the constructor.
  • Line {4}: create an empty array assigning empty brackets...
lock icon The rest of the chapter is locked

Subscribe to access the full title

Advance your knowledge in tech

A Packt subscription gives you instant online access to our library of over 8,000 practical eBooks and videos, constantly updated with the latest in tech
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant