𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗔𝗿𝗿𝗮𝘆𝘀
JavaScript arrays store lists of values in order. You access each value through an index.
Key facts about arrays:
• They are objects, not primitives. • They resize automatically. • They hold different data types at once. • Use typed arrays if you need strict data types.
How to use them:
You declare an array like this: let fruits = ["Apple", "Orange", "Plum"];
You access the first item like this: alert(fruits[0]);
Rules to remember:
- Arrays use zero-based indexing. The first item sits at index 0. The last item sits at the length minus 1.
- You cannot use strings as indexes. You must use non-negative integers.
- Copying an array creates a shallow copy. This means nested objects stay linked to the original array.
Source: https://dev.to/karthick_07/mastering-javascript-arrays-techniques-and-best-practices-287e