Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Spreadsheet Automation 101 Lesson 2: Bracket Notation

About this Tutorial

Learn how and when to use Bracket Notation in an array. No memorization is needed!. You’ll also be able to see the gap between what it is that’s missing.

Video Transcript

<div>00:01 Hello, welcome to BRCA Notations. So this is pretty cool. And probably one of the weirdest and mind altering kinds of parts of learning app script Learn about Google Apps Script and how it enhances your spreadsheet capabilities. Opens in new tab .<br>00:13 BRCA notation Discover different types of notations used in programming and scripting. Opens in new tab is used whenever we have an array. So arrays Understand arrays and their importance in managing data in scripts. Opens in new tab are very important when dealing with app script Learn about Google Apps Script and how it enhances your spreadsheet capabilities. Opens in new tab , especially in like emailing many people or or anytime we're just managing lots of data Explore how to handle and manipulate data effectively in spreadsheets. Opens in new tab in like a row or a column or in a table Get insights on organizing data in tables for better readability. Opens in new tab of rows and columns.<br>00:29 And we wanna parse that data Explore how to handle and manipulate data effectively in spreadsheets. Opens in new tab , right?

We wanna go through the for loop and we wanna access sort Learn techniques for sorting data in your spreadsheets. Opens in new tab of all parts of that array.<br>00:40 Because what happens is when we use dot get values Understand how to work with values in your spreadsheet functions. Opens in new tab spreadsheet Dive into the features and functionalities of spreadsheets. Opens in new tab app and all that stuff, and then get values Understand how to work with values in your spreadsheet functions. Opens in new tab of a range Learn about ranges and how to manipulate them in your scripts. Opens in new tab , it creates an array for us.<br>00:49 So I wanted to go through bracken notation Discover different types of notations used in programming and scripting. Opens in new tab and get this show you lots of ways to do it because, and lots of ways to figure it out because I could sort Learn techniques for sorting data in your spreadsheets. Opens in new tab of explain it to you all and it might just wash over your head, such as it did for me.<br>01:09 Only when I started using it and understanding how to use it did I figure out, I didn't really have to memorize it, I just had to know the process of figuring it out.<br>01:18 So bracket notation Discover different types of notations used in programming and scripting. Opens in new tab is pretty simple.

It has these brackets and around some type of array, we'll name that array and then that bracket, this, these brackets will be around a number Explore how to work with numbers in your spreadsheet calculations. Opens in new tab .<br>01:32 So the number Explore how to work with numbers in your spreadsheet calculations. Opens in new tab zero or one or two, three, or in the case of four loops, we'll use I a lot.<br>01:39 And this is going to tell, this is going to tell the script to get which element of the array arrays Understand arrays and their importance in managing data in scripts. Opens in new tab are always like in an order from 0 1 2 to n and having array zero in brackets will, will be the first item.<br>02:03 Now, if you have an array inside of an array or an array of arrays Understand arrays and their importance in managing data in scripts. Opens in new tab , which you can have you'll access by two brackets.<br>02:11 And the first item of the first array will be zero, zero.

And then you can also say, the second item of the first array is gonna be zero one, the second array, but the first item is gonna be one zero.<br>02:28 And I'll show you, you don't have to memorize this in any way. You just have to follow along as we do in here, and I'll show you sort Learn techniques for sorting data in your spreadsheets. Opens in new tab of how to figure it out, right?<br>02:38 We may make some mistakes and we may learn it as we go and experience it. So let's first start a function Understand the role of functions in spreadsheet automation. Opens in new tab , right?<br>02:48 We just start any function Understand the role of functions in spreadsheet automation. Opens in new tab , and we can create an array. We can create an array in two ways.

We can say variable, just name any array.<br>02:57 And this new array with a capital A and parenthesis must have parenthesis on here. Or we can just use these two brackets to create a new array.<br>03:09 We can log, let's log this in array and log another array and just see what they are. And I want to do this because I like showing you that you should be using logger a lot.<br>03:26 This is a way to figure stuff out and see they're the same thing.

One note Discover how to add notes and comments in your spreadsheets. Opens in new tab I will mention is that you may know that in the logger we can write like this is an array in a string Learn about strings and their usage in scripting. Opens in new tab and then add it to this so that it combines it.<br>03:46 Something will happen though, and I want to, I want to you to see this. If we run this again, Notice the brackets are gone.<br>03:56 This is an array, has nothing in it. It's because it's an empty array. So it has no items, but the brackets are gone.<br>04:02 Why is that?

That's because when we add a string Learn about strings and their usage in scripting. Opens in new tab at the beginning of this, it will string Learn about strings and their usage in scripting. Opens in new tab a file, turn this array into a string Learn about strings and their usage in scripting. Opens in new tab .<br>04:09 So let's say we, instead of another array, we actually have it item one, item two, item three. Let's say that.<br>04:20 And when we log it, it will show up. Item one is not defined. I think it needs to actually be in quotes.<br>04:28 That's why &lt;laugh&gt; it's thinking it's a variable. So let's put in quotes, these three strings. There you go. Item one, item two, item three.<br>04:40 And now if we put this, let's see what happens if we do this.

This is another great, and again, I'm showing this to you.<br>04:50 Oh, we need to add a plus so that, you know, you can do this too if you need to process and figure out what am what are you doing in your script?<br>04:57 Or if you copy and paste a script from online and it has a raise, these are how you can figure out what a rays are doing And check this out.<br>05:07 So it combined them with, with commas, and it took the quota out, right?

So it took each of those items and put it in here.<br>05:17 And that's because it, it, the first thing in here is a string Learn about strings and their usage in scripting. Opens in new tab , and it's trying, and it turns the array into a string Learn about strings and their usage in scripting. Opens in new tab .<br>05:23 But let's see if we don't have that, it's an array. So it has those brackets. So those two things are the same when logged it and with a string Learn about strings and their usage in scripting. Opens in new tab , it changes it to a string Learn about strings and their usage in scripting. Opens in new tab .<br>05:37 Okay, let's look at bracket notation Discover different types of notations used in programming and scripting. Opens in new tab . Now that we have an array, now that we have our arrays Understand arrays and their importance in managing data in scripts. Opens in new tab we can also create a third array.<br>05:48 And this one is going to be an array of arrays Understand arrays and their importance in managing data in scripts. Opens in new tab .

So we have AUM one, AUM two, and in this second part we'll put item three, so we can see how to get those.<br>06:05 Let's log it as well. Log this third array and it will set up our pallet. Our what we're going to be using bracket notation Discover different types of notations used in programming and scripting. Opens in new tab to get to.<br>06:19 So we have two different brackets two different arrays Understand arrays and their importance in managing data in scripts. Opens in new tab here, and we're going to access them through bracket notation Discover different types of notations used in programming and scripting. Opens in new tab . How do we do that?<br>06:27 Here's what we do. We just name, we just name the array. Let's do logger. So it's gonna be in the case of the, another array.<br>06:38 Just name it, put the name and then bracket zero.

And in this bracket, what it'll do is it should get this item one, And it did.<br>06:49 So it's the first item in this array. So it's one array across, and it's getting the first item in that array.<br>06:57 If we do bracket one, it should give us item two. Now, it's always good to give a little hypothesis first, run it and see what ha what happens, right?<br>07:08 Execute it. And we have item two in our log. We can also just for so sweet, see one to simplify what we're running here, let's run that again.<br>07:18 Item two, right? We're using the bracket notation Discover different types of notations used in programming and scripting. Opens in new tab in two brackets.

And the number Explore how to work with numbers in your spreadsheet calculations. Opens in new tab one, again, super simple. If we use number Explore how to work with numbers in your spreadsheet calculations. Opens in new tab two and run it, it will give us item three.<br>07:31 Okay? So again, arrays Understand arrays and their importance in managing data in scripts. Opens in new tab start with zero and go to N. However many items are in the array. Now, this third array, how do we access that?<br>07:41 Well, let's see what happens if we go third array and bracket zero. Let's run that. We're getting the first item, which is an array item one and two.<br>07:55 So these are two arrays Understand arrays and their importance in managing data in scripts. Opens in new tab inside of one array. So it's first array, then the second array, then third array.

So now let's see what happens if we put in one.<br>08:06 Now, if your guess, my guess is that it'll be item three. Right? And this is a simple, I've sorry to set this up.<br>08:12 It should not be item two and correct, it's item three. Okay? So this now is different than the one up here.<br>08:23 So how do we access the second item in the first item? So item two, we would theoretically do something like this.<br>08:35 Zero one with two brackets. Let's see, let's, let's see if it works. Item two.

Now, if we do, I zero zero here in these brackets, We get item one, right?<br>08:47 So it's a first item of the first item, and they're all in order, right? It's all ordered. This is not necessarily rows and columns or a, a table Get insights on organizing data in tables for better readability. Opens in new tab .<br>08:55 It is every array is an order of items. What's really cool about this is that we can create different arrays Understand arrays and their importance in managing data in scripts. Opens in new tab that all have the same order, and then we can take out parts with the if and push it, right?<br>09:10 We can do something like take array. Let's take this another array, push and put item four.

So now that we take an array and we push one more item to it, pushing just means that we're adding one item to this array.<br>09:30 I wanna log this new array, the, the array that it, the new array. Let's see. So now it is exactly the same array as before, except it has a fourth item, item four.<br>09:48 So we can use push to keep adding items to an array. We can use bracken notation Discover different types of notations used in programming and scripting. Opens in new tab to identify what is the item, the thing, the element, the part of the array that we want to get.<br>10:00 This is really cool and I hope this was really helpful to understand bracket notation Discover different types of notations used in programming and scripting. Opens in new tab .

And you don't necessarily have to memorize this, right?<br>10:10 So if out of all of this, you, you forget everything else, and you only have to, and you can only remember one thing, remember to just try it, try to access things, especially if you're using I and in an a four loop and things are just not working out correctly.<br>10:27 Just try to get one item, get one thing out of it using this bracken notation Discover different types of notations used in programming and scripting. Opens in new tab .&nbsp; Again, we can use I here in a four loop, but just go ahead and try to log something like zero and something like zero.<br>10:41 See what happens.

Log it, look at it, look at what it gets, get a hypothesis, what it gets, and then you'll see the gap between what it is that's missing.<br>10:55 Also try to push things to an array. One of the most common mistakes that happens is that we don't create an array.<br>11:03 So theran doesn't exist.

So when we push to it, like, or we can't or we don't push anything to it, right?<br>11:10 In in four loops, a lot of times we are trying to just get a few items out of a larger array or a larger list of items Explore how to create and manage lists of items in your scripts. Opens in new tab , and we just end up not pushing it.<br>11:20 We're like, okay, we get the, the correct if calculation Understand the basics of calculations in spreadsheets. Opens in new tab , and then we're like, okay, return the thing and we only, and we return each of those items, but we don't add them all to a new array.<br>11:33 So we'll only get like the last item out of it. We'll return the last item, which is not cool.

So you can create a new array by literally saying new array with a capital A and parenthesis.<br>11:46 That's very key to remember, or variable new array equals, and you're just gonna have two empty brackets. And sure you can create an array with items.<br>12:00 Actually, that's one good thing to do.

If you're trying to debug your app script Learn about Google Apps Script and how it enhances your spreadsheet capabilities. Opens in new tab in, and you're like, okay, I'm grabbing the information from this page and I'm putting it into this array, and then I'm taking this array and I'm go doing a for loop on it, or I'm accessing it through this BRCA notation Discover different types of notations used in programming and scripting. Opens in new tab and it's getting, it's not getting anything undefined, or it's or it's a wrong thing.<br>12:25 Try to create the array that you think it is as just text.

So just call it that and see if the actions you're taking are correct, right?<br>12:36 So if the act, if you create the array you think you're creating and the actions are correct, then you'll get the right answer.<br>12:42 And so the actual problem will be at the beginning where Learn about querying data with where clauses in your scripts. Opens in new tab you get the array. Sometimes Google Sheets is really funky.<br>12:50 Sometimes when you're grabbing like all of the, the entire row Discover how to work with entire rows in your spreadsheet. Opens in new tab , it'll be a different syntax Get familiar with the syntax used in scripting and programming. Opens in new tab in the array than if you could grab an entire column Learn how to manipulate entire columns in your spreadsheet. Opens in new tab .<br>13:02 It'll be like an array, one array or it'll be an array of arrays Understand arrays and their importance in managing data in scripts. Opens in new tab .

So there's different ways to access that array, either using two or one bracket notation Discover different types of notations used in programming and scripting. Opens in new tab .<br>13:14 So I hope this was helpful in some way to help you through bracket notation Discover different types of notations used in programming and scripting. Opens in new tab and understand how to access these, because this is really, really powerful.<br>13:24 I really love working with arrays Understand arrays and their importance in managing data in scripts. Opens in new tab and being able to access like empowered to access them in this way especially with the Four Loop.<br>13:36 Hopefully. And, and also if you have any questions, feel free to ask Bite.</div>

Courses

Spreadsheet Automation 101: Introduction to Pre-course Videos

Think Like a Programmer: Develop The Mindset of an Apps Script Coder

How To Change Date Format Automatically

Tips to Navigating Thousands of Lines of Code In Apps Script

Spreadsheet Automation 101: Functions

Spreadsheet Automation 101: Variables

Spreadsheet Automation 101: Dot Notation

Spreadsheet Automation 101: Camel Case

Spreadsheet Automation 101: Parentheses

Spreadsheet Automation 101 Lesson 1: GetValue - Introduction to SpreadsheetApp

Spreadsheet Automation 101 Lesson 1: Spreadsheet Taxonomy

Spreadsheet Automation 101 Lesson 1: A1 Notation vs Row,Column Syntax

Spreadsheet Automation 101 Lesson 1: getActiveSpreadsheet() vs getActiveSheet()

Spreadsheet Automation 101 Lesson 1: onOpen() Trigger - Custom Menu

This Seems Like Automation

Spreadsheet Automation 101 Lesson 2: Get Values - Introduction

Spreadsheet Automation 101 Lesson 2: Arrays

Spreadsheet Automation 101 Lesson 2: For Loop

Spreadsheet Automation 101 Lesson 2: Bracket Notation

Spreadsheet Automation 101 Lesson 2: Logger.log()

Spreadsheet Automation 101 Lesson 2: If ( ){ } and Checkboxes

Spreadsheet Automation 101 Lesson 2: onEdit() Trigger

Introduction to Spreadsheet Automation 101 Lesson 3

Spreadsheet Automation 101 Lesson 3: MailApp

Spreadsheet Automation 101 Lesson 3: Email Yourself For Loop

Spreadsheet Automation 101 Lesson 3: Send Email Every Week Trigger

Spreadsheet Automation 101 Lesson 3: Email Other People For Loop

Spreadsheet Automation 101 Lesson 4: Access APIs Introduction

Spreadsheet Automation 101 Lesson 4: UrlFetchApp

Spreadsheet Automation 101 Lesson 4: OmdbAPI get ApiKey, get Data in URL

Spreadsheet Automation 101 Lesson 4: OmdbAPI get data in Apps Script

Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters

Spreadsheet Automation 101 Lesson 4: OmdbAPI Parameter Picker

Automatically Clear Content | Refresh Reuse Recycle Templates

Automate Google Sheets With Zero Experience

Automatically Uncheck A Daily Checklist

Activate A Certain Sheet When Opening a Spreadsheet

Scoping Functions in Apps Script

Breaking Through Errors In Apps Script

VAR vs CONST vs CONSTANT in Apps Script