𝗔𝗿𝗿𝗮𝘆𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁
An array stores multiple values in one variable. Instead of creating separate variables for every item, you group them together.
Creating an Array You create an array using square brackets. This method is the simplest way to start.
Example: const bikes = ["pulser", "apache", "duke"];
Key Facts About Arrays
- Arrays are objects. The typeof operator returns "object" when you check an array.
- Arrays use numbers to access items. The first item is always at index 0.
- Arrays can hold different types. You can store strings, numbers, objects, or even other arrays in one list.
- JavaScript does not support associative arrays. You cannot use names as indexes. You must use numbers.
Common Tasks
Convert to String Use the toString() method to turn an array into a comma-separated string.
Add New Items Use the push() method to add an item to the end of your list.
Loop Through Items Use a for loop to go through every item in your array one by one.
Arrays vs Objects
Choose an array when your data uses numbers as indexes. Choose an object when your data needs text names for each value.
Nested Data You can put objects inside arrays. You can also put arrays inside objects. This allows you to organize complex data structures.
Source: https://www.w3schools.com/js/js_arrays.asp Source: https://www.geeksforgeeks.org/javascript/best-known-javascript-array-methods/
Full Post: https://dev.to/ezhil_arasan_d1230a486501/array-in-javascrip-1hna