- An array is an ordered list of values, written with square brackets:
["a", "b", "c"]. - Items are accessed by index, starting at 0. The last item is at
length - 1(or use.at(-1)). - Reading an index that doesn't exist gives
undefined. constarrays can still have their contents changed. You just can't replace the whole array.push/popadd/remove at the end.unshift/shiftadd/remove at the start.includeschecks if an item exists.indexOffinds its position (or-1).slicecopies part of an array (original unchanged).spliceremoves/inserts items in the original.- Loop with
for (let i = 0; i < arr.length; i++)when you need the index, orfor...ofwhen you just need the items. splitturns a string into an array.jointurns an array into a string.- Spread (
[...arr]) copies or combines arrays. Plain assignment (b = a) does not copy; both names share one array. sort()sorts as text by default! For numbers, usesort((a, b) => a - b).- Arrays can contain arrays, which is great for grids:
grid[row][col].
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.