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

Transforming an array

JavaScript also has support to methods that can modify the elements of the array or change its order. We have covered two transformative methods so far: reverse and sort. Let's learn about other useful methods that can transform the array.

Mapping values of an array

The map method is one of the most used methods in daily coding tasks when using JavaScript or TypeScript. Let's see it in action:

const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const squaredNumbers = numbers.map(value => value * value);
console.log('Squared numbers:', squaredNumbers);

Suppose we would like to find the square of each number in an array. We can use the map method to transform each value within the array and return an array with the results. For our example, the output will be: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100].

We could rewrite the preceding code using a for loop to achieve the same result:

const squaredNumbersLoop = [];
for (let i = 0; i < numbers.length...
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