Menu

Post image 1
Post image 2
1 / 2
0

JavaScript Arrays 101

DEV Community·Pratham·23 days ago
#GQlj34Eu
#part#accessing#why#fullscreen#array#index
Reading 0:00
15s threshold

Your first real data structure — and the one you'll use more than any other. Let me paint a picture. You're building a to-do app. You've got 5 tasks. So you do the "logical" thing: let task1 = " Buy groceries " ; let task2 = " Finish homework " ; let task3 = " Call mom " ; let task4 = " Go to gym " ; let task5 = " Read a chapter " ; Enter fullscreen mode Exit fullscreen mode Five variables for five tasks. Now imagine you have 50 tasks. Or 500. Are you going to create 500 separate variables? Obviously not. That's insane. And even with just 5, how do you loop through them? How do you add a new one? How do you remove one? This is exactly the problem arrays solve. And once you get comfortable with them, you'll wonder how you ever wrote JavaScript without them. What Is an Array? An array is an ordered collection of values stored under a single variable name. Instead of creating a separate variable for each value, you put them all in one place — like a numbered list. Think of it as a row of lockers .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More