User Guide

Linear lists and property lists 43
Adding and deleting items in lists
You can add or delete items in a list by using the following methods.
To add an item at the end of a list, use the append() method.
To add an item at its proper position in a sorted list, use the add() or addProp() methods.
To add an item at a specific place in a linear list, use the addAt() method.
To add an item at a specific position in a property list, use the addProp() method.
To delete an item from a list, use the deleteAt(), deleteOne(), or deleteProp() methods.
To replace an item in a list, use the setAt() or setaProp() methods.
The following statements use
append() to add an item to the end of a list.
-- Lingo syntax
workerList = ["Bruno", "Heather", "Carlos"] -- define a linear list
workerList.append("David")
trace(workerList) -- displays ["Bruno", "Heather", "Carlos", "David"]
// JavaScript syntax
var workerList = list("Bruno", "Heather", "Carlos"); // define a linear list
workerList.append("David");
trace(workerList); // displays ["Bruno", "Heather", "Carlos", "David"]
The following statements use addProp() to add a property and an associated value to a
property list.
-- Lingo syntax
-- define a property list
foodList = [#breakfast:"Waffles", #lunch:"Tofu Burger"]
foodList.addProp(#dinner, "Spaghetti") -- adds [#dinner: "Spaghetti"]
// JavaScript syntax
// define a property list
var foodList = propList("breakfast", "Waffles", "lunch", "Tofu Burger");
foodList.addProp("dinner", "Spaghetti"); // adds ["dinner": "Spaghetti"]
You do not have to explicitly remove lists. Lists are automatically removed when they are no
longer referred to by any variable. Other types of objects must be removed explicitly, by setting
variables that refer to them to
VOID (Lingo) or null (JavaScript syntax).
Copying lists
Assigning a list to a variable and then assigning that variable to a second variable does not make a
separate copy of the list. For example, the first statement below creates a list that contains the
names of two continents, and assigns the list to the variable
landList. The second statement
assigns the same list to a new variable
continentList. In the third statement, adding Australia
to
landList also automatically adds Australia to the list continentList. This happens
because both variable names point to the same list object in memory. The same behavior occurs
by using an array in JavaScript syntax.
-- Lingo syntax
landList = ["Asia", "Africa"]
continentList = landList
landList.add("Australia") -- this also adds "Australia" to continentList