The documentation covers essential array operations, including creation, reading, modification, and various operations such as finding locations, reversing, and inserting and deleting values at specific positions.
Create
Setting a number array
Set list to array of
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable></variables><block type=\"variables_set\" disabled=\"true\" x=\"-23\" y=\"68\"><field name=\"VAR\">list</field><value name=\"VALUE\"><block type=\"lists_create_with\" disabled=\"true\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value><value name=\"ADD1\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">1</field></shadow></value></block></value></block></xml>"}
This block is used to set the number array into variable.
Parameters: Number (Default:0, 1)
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>value</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"ADD1\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"pxt_controls_for_of\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">value</field></shadow></value><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><statement name=\"DO\"><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value></block></value></block></statement></block></next></block></statement></block></xml>"}
The output:

Setting a Text Array
Set text list to array of
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>value</variable><variable>text list</variable></variables><block type=\"variables_set\" disabled=\"true\" x=\"70\" y=\"284\"><field name=\"VAR\">text list</field><value name=\"VALUE\"><block type=\"lists_create_with\" disabled=\"true\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></xml>"}
This block is used to set the text array into variable.
Parameters: String (Default: a, b, c)
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></statement></block></xml>"}
The output:

Creating New Array
Empty array
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"lists_create_with\" disabled=\"true\" x=\"-22\" y=\"292\"><mutation items=\"0\" horizontalafter=\"3\"/></block></xml>"}
This block is used to create a new array.
Parameters: Screen Item
Output: Array
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>array</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"22\" y=\"383\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">array</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><block type=\"text\"><field name=\"TEXT\">text 1</field></block></value><value name=\"ADD1\"><block type=\"text\"><field name=\"TEXT\">text 2</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">array</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">array</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></statement></block></xml>"}
The output:

Read
Counting the Length of an Array
Length of array list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>array</variable><variable>index</variable><variable>list</variable></variables><block type=\"lists_length\" disabled=\"true\" x=\"112\" y=\"293\"><value name=\"VALUE\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used show the number of items in the array.
Parameters: Screen Item (Array)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value></block></next></block></statement></block></xml>"}
The output:

Showing the Value with the Selected Index
List get value at
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>list</variable></variables><block type=\"lists_index_get\" disabled=\"true\" x=\"-22\" y=\"472\"><value name=\"LIST\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to show the value at the given index in an array.
Parameters:
- Screen Item (Array)
- Number
Output: Screen Item
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></next></block></statement></block></xml>"}
The output:

Showing the Value that will be Removed
List get and remove value at
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>list</variable></variables><block type=\"array_removeat\" disabled=\"true\" x=\"-22\" y=\"338\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value><value name=\"index\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to show and remove the value at the certain index.
Parameters:
- Screen Item (Array)
- Number
Output: Screen Item
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"array_removeat\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"index\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value></block></next></block></statement></block></xml>"}
The output:

Showing and Removing the Last Item
Get and remove last value from list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>list</variable></variables><block type=\"array_pop\" disabled=\"true\" x=\"-22\" y=\"383\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to show and remove the last value inside array.
Parameters: Screen Item (Array)
Output: Screen Item
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"array_removeat\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"index\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value></block></next></block></statement></block></xml>"}
The output:

Showing and Removing the First Item
Get and remove first value from list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>list</variable></variables><block type=\"array_shift\" disabled=\"true\" x=\"-22\" y=\"338\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to show and remove the first value inside array.
Parameters: Screen Item (Array)
Output: Screen Item
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"array_shift\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"typescript_expression\"><field name=\"EXPRESSION\">\"After removing th e value, the remaining values are:\"</field></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}
The output:

Showing a Random Value
Get random value from list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"array_pickRandom\" disabled=\"true\" x=\"-22\" y=\"652\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
Modify
Modifying the Value Inside Array
List set value at 0 to
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"lists_index_set\" disabled=\"true\" x=\"23\" y=\"563\"><value name=\"LIST\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to modify the value at the selected location in the array.
Parameters: Screen Item (Array)
Condition:
- Number (Default: 0)
- Screen Item
Output: N/A
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"lists_index_set\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"VALUE\"><shadow type=\"text\"><field name=\"TEXT\">d</field></shadow></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Inserting the Value at the End
List add value … to end
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"array_push\" disabled=\"true\" x=\"23\" y=\"292\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to add the value at the end of the array.
Parameters:
- Screen Item (Array)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_push\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"value\"><shadow type=\"text\"><field name=\"TEXT\">END</field></shadow></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Deleting Last Value
Remove last value from list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"array_pop_statement\" disabled=\"true\" x=\"23\" y=\"518\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to delete the last value in the array.
Parameters:
- Screen Item (Array)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_pop_statement\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Deleting First Value
Remove first value from list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"array_shift_statement\" disabled=\"true\" x=\"23\" y=\"472\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to delete the first value in the array.
Parameters:
- Screen Item (Array)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">text_list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_shift_statement\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">text_list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Adding Value at the Beginning
List insert … at beginning
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>text_list</variable><variable>index</variable><variable>list</variable></variables><block type=\"array_unshift\" disabled=\"true\" x=\"-22\" y=\"427\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used add one value at the beginning of an array.
Parameters:
- Screen Item (Array)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>insert</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">insert</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"array_unshift\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"value\"><shadow type=\"text\"><field name=\"TEXT\">START</field></shadow></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Inserting Value at the Beginning
List insert at beginning
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>insert</variable><variable>index</variable></variables><block type=\"array_unshift_statement\" disabled=\"true\" x=\"23\" y=\"517\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used add one value at the beginning of an array.
Parameters:
- Screen Item (Array)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_unshift_statement\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"value\"><shadow type=\"text\"><field name=\"TEXT\">START</field></shadow></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Adding Value in the Certain Place
List insert at 0 value
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"array_insertAt\" disabled=\"true\" x=\"23\" y=\"607\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value><value name=\"index\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to add one value at the certain location.
Parameters:
- Screen Item (Array)
- Condition: Number (Default: 0)
- Screen Item
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_insertAt\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"index\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value><value name=\"value\"><shadow type=\"text\"><field name=\"TEXT\">hello</field></shadow></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Deleting Value at a Certain Location
List remove value at
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"array_removeat_statement\" disabled=\"true\" x=\"0\" y=\"0\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value><value name=\"index\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to delete the value at a certain location.
Parameters:
- Screen Item (Array)
- Condition: Number (Default: 0)
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_removeat_statement\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"index\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Operations
Finding the Location of a Value
List find index of
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"array_indexof\" disabled=\"true\" x=\"-22\" y=\"607\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to find the location of a value.
Parameters:
- Screen Item (Array)
- Condition: String/Number
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>find</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">find</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"array_indexof\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"value\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"variables_get\"><field name=\"VAR\">find</field></block></value></block></next></block></next></block></statement></block></xml>"}
The output:

Reversing the Array
Reverse list
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>find</variable></variables><block type=\"array_reverse\" disabled=\"true\" x=\"23\" y=\"697\"><value name=\"list\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">list</field></block></value></block></xml>"}
This block is used to reverse the value in the array.
Parameters: Screen Item (Array)
Output: N/A
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>list</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">list</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"array_reverse\"><value name=\"list\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">list</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>"}
The output:

Table of Content