๐Ÿ–จ๏ธ COSMOS PRINTER
๐Ÿšš Shipping from 12 USD
๐Ÿ’ฐ DEALS OF THE DAY

Arrays

Basics

Arrays are ordered lists of values and can hold values of any type, including numbers, strings, and other arrays.

Please note that using big arrays will significantly increase the size and memory usage of your program, and both are quite limited for MagiScript. If you need more than a few tens of elements, you should use Uint8Array or our database feature (which will be implemented later).

Creating an Array

To create an array you can use the following syntax:

				
					let myArray = [1, 2, 3, "four", true];
				
			

This creates an array calledย myArray, which contains the valuesย 1,ย 2,ย 3,ย "four", andย true.

Accessing Array Elements

You can access elements in an array using the square bracket notation:

				
					let myArray = [1, 2, 3, "four", true];

console.log(myArray[0]); // Output: 1
console.log(myArray[3]); // Output: four
				
			

In the above example, we access the first element of the array usingย myArray[0], and the fourth element usingย myArray[3].

Length of an Array

Arrays have aย lengthย property, which returns the number of elements in the array:

				
					let myArray = [1, 2, 3, "four", true];

console.log(myArray.length); // Output: 5
				
			

In the above example, we access theย lengthย property of theย myArrayย array usingย myArray.length.

Modifying Array Elements

You can modify elements in an array using the square bracket notation as well:

				
					let myArray = [1, 2, 3, "four", true];

myArray[1] = "two";

console.log(myArray[1]); // Output: two
				
			

In the above example, we modify the second element of theย myArrayย array by setting it toย "two"ย usingย myArray[1].

Iterating Over the Elements of an Array

You can use aย forย loop to iterate over every element of an array:

				
					let myArray = [1, 2, 3, "four", true];

for (let index = 0; index < myArray.length; index++) {
  console.log(myArray[index]);
}
				
			

Conclusion

Arrays in MagiScript are similar to arrays in JavaScript. They are created using square brackets, and you can access elements using the square bracket notation. They also have aย lengthย property, which returns the number of elements in the array. At this time, there are no other methods available for arrays in MagiScript.

General

๐Ÿ“ƒ First Steps

MagiScript Editor

๐Ÿ“ƒ Basics

๐Ÿ“ƒ Keyboard Shortcuts

๐Ÿ“ƒ Running Your First Program

๐Ÿ“ƒ App Store

๐Ÿ“ƒ Atom Settings (Editor)

๐Ÿ“ƒ Debugging Techniques

Examples

๐Ÿ“ƒ Atom Time

๐ŸŽž๏ธ Time Practice

๐Ÿ“ƒ Atom Pi (Pi Revelations)

๐Ÿ“ƒ Atom Drum

๐ŸŽž๏ธ Atom Stack

๐Ÿ“ƒ Atom Square

๐Ÿ“ƒ Atom Level

๐Ÿ“ƒ Atom THMPR

๐Ÿ“ƒ Poker Hands

๐Ÿ“ƒ Keyboard Numeric

๐Ÿ“ƒ Keyboard NOKIA

๐Ÿ“ƒ Keyboard Cursor

๐Ÿ“ƒ Keyboard Media

๐Ÿ“ƒ Keyboard Custom

Input/Output

๐Ÿ“ƒ Buttons

๐Ÿ“ƒ Vibration Motor

๐Ÿ“ƒ RGB LED

๐Ÿ“ƒ Devices

๐Ÿ“ƒ PeekSmith

๐Ÿ“ƒ Quantum

๐Ÿ“ƒ Teleport

๐Ÿ“ƒ Spotted Dice

๐Ÿ“ƒ SB Watch

๐Ÿ“ƒ IARVEL Watch

๐Ÿ“ƒ Fossil Watch

๐Ÿ“ƒ Cosmos Printer

๐Ÿ“ƒ PeriPage Printer

๐Ÿ“ƒ ATC Remote

๐Ÿ“ƒ Labko Scrabble

๐Ÿ“ƒ Bluetooth Keyboard

๐Ÿ“ƒ Bluetooth Mouse

๐Ÿ“ƒ Timers

๐Ÿ“ƒ Database

๐Ÿ“ƒ Events

๐Ÿ“ƒ System (exit, sleep, rand)

๐Ÿ“ƒ Objects (card, time)

Language

๐Ÿ“ƒ Summary

๐Ÿ“ƒ Comments

๐Ÿ“ƒ Variable Declarations

๐Ÿ“ƒ Operators

๐Ÿ“ƒ Control Flow

๐Ÿ“ƒ Functions

๐Ÿ“ƒ Numbers

๐Ÿ“ƒ Strings

๐Ÿ“ƒ Arrays

๐Ÿ“ƒ Objects

๐Ÿ“ƒ Uint8Array