βœ… NEW PRODUCTS
🚚 Shipping from 12 USD
πŸ’° DEALS OF THE DAY

Uint8Array

About

The Uint8Array is a built-in data structure in MagiScript which allows you to store an array of 8-bit unsigned integers (values between 0 and 255). This data structure is particularly useful when you need to store a large number of small integers in a memory-efficient way.

It is a specialized array, with fix length and restricted values.

Creating a Uint8Array

You can create aΒ Uint8ArrayΒ by calling theΒ newUint8ArrayΒ function with a single argument: the size of the array. For example, the following code creates aΒ Uint8ArrayΒ with 10 elements:

				
					let myArray = newUint8Array(10);
				
			

Accessing Array Items

You can access the elements of aΒ Uint8ArrayΒ using the bracket notation ([]). The index of the first element isΒ 0, and the index of the last element isΒ length - 1.

For example, the following code sets the first element of theΒ myArrayΒ toΒ 42:

				
					myArray[0] = 42;
				
			

And the following code retrieves the value of the third element:

				
					let thirdElement = myArray[2];
				
			

Querying the Length

You can query the length of aΒ Uint8ArrayΒ using theΒ lengthΒ property. For example, the following code prints the length of theΒ myArray:

				
					console.log(myArray.length);
				
			

Example

The following code creates a Uint8Array with 5 elements, sets their values to 0, 1, 2, 3, and 4, respectively, and then prints them:

				
					let myArray = newUint8Array(5);

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

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

This will output the numbers from 0 to 5.

Conclusion

The Uint8Array is a memory-efficient data structure that allows you to store an array of 8-bit unsigned integers in MagiScript. You can create a Uint8Array by calling the newUint8Array function with a single argument: the size of the array. You can access the elements of a Uint8Array using the bracket notation, and query its length using the length property.

Devices & MagiScript

βš›οΈ Atom Remote

πŸ”’ Quantum Calculator

πŸ€Ήβ€β™‚οΈ MagiScript Language

πŸ€Ήβ€β™‚οΈ MagiScript Examples

πŸ€Ήβ€β™‚οΈ MagiScript Tutorials

General

πŸ“ƒ First Steps

MagiScript Editor

πŸ“ƒ Basics

πŸ“ƒ Keyboard Shortcuts

πŸ“ƒ Running Your First Program

πŸ“ƒ App Store

πŸ“ƒ Atom Settings (Editor)

πŸ“ƒ Debugging Techniques

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

πŸ“ƒ Labco 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