University of Sydney · FACULTY OF COMPUTER SCIENCE

IDEA9103 Chap.9 Objects, Arrays and Property Access

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 9 of 10 · IDEA9103

Objects, Arrays and Property Access

Objects group related values under descriptive keys, while arrays organise values by zero based position. This chapter models shapes as objects, collections as arrays and nested access as a left to right chain. Dot notation suits known property names, bracket notation accepts a runtime key, and the last array item always sits at length minus one rather than at the length itself.

In this chapter

What this chapter covers

  • 01

    Object literal notation

  • 02

    Key value pairs

  • 03

    Dot notation

  • 04

    Bracket notation

  • 05

    Zero based arrays

  • 06

    Length and last index

Worked example · free

Read a palette of shape objects

Q [4 marks]. The practice mark allocation used here is not part of the University's published assessment scheme. Three shape objects are stored in order with amber, teal and violet fills. Retrieve the second and last fills.
The object panel organises named properties, while the array panel organises values by zero-based positions from left to right.The object panel organises named properties, while the array panel organises values by zero-based positions from left to right.objectx: 40y: 90fill: coralarray0123
The object panel organises named properties, while the array panel organises values by zero-based positions from left to right.
  • 1The array length is three.
  • 1The second object is at index one.
  • 1shapes[1].fill returns teal.
  • 1shapes[shapes.length - 1].fill returns violet.
Zero based indexing selects the object, then property access selects its named fill value.
Sia tip — Treat length as a count. The final valid position is always one less than that count.
Glossary

Key terms

Object
A JavaScript reference value that groups related data through named properties.
Key value pair
A property name associated with the value stored for that property.
Dot notation
A concise property access form used when the key name is known directly.
Bracket notation
A property or array access form that can evaluate a key or index expression.
Zero based index
An array position system in which the first item is numbered zero.
FAQ

Objects, Arrays and Property Access FAQ

Why model a shape as an object?

A shape has related attributes such as x, y, width and fill. Named properties preserve what each value means and allow code to access one attribute without depending on property order.

When is bracket notation better than dot notation?

Bracket notation is necessary when the property name is held in a variable or computed during execution. Dot notation is clearer when the exact key is known while writing the code.

Why is the final array index length minus one?

Length counts how many items the collection contains, while indices begin at zero. A collection of five items therefore has valid positions zero through four, making four equal to length minus one.

How do arrays and objects work together in a creative sketch?

Use an array to preserve the order of repeated elements and an object to preserve the meaning of each element's attributes. An array of shape objects can answer which shape comes second, while the selected object can answer what its x position or fill is. This combination survives design changes better than parallel unexplained lists.

Reordering shapes changes their indices, but the property name fill continues to identify the same kind of attribute within every well-formed object.

How should I debug a nested access expression?

Evaluate it from left to right and store each intermediate result temporarily. Confirm the array exists, check that the requested index is valid, inspect the item at that position and only then read the named property. If bracket notation uses a variable, log the variable's exact string as well.

Breaking shapes[1].fill into observable stages identifies whether undefined came from the collection, position, item structure or key spelling instead of surrounding the entire expression with guesswork.

What should happen when an array is empty?

Make the boundary case part of the algorithm. Because length minus one becomes negative, the code should skip the access, provide a documented fallback or create an initial item before reading the last element. Choose the response that matches the creative rule. Optional access can prevent an exception, but it does not decide what the artwork should display.

An explicit empty-state branch preserves meaning and makes later testing possible with both empty and populated collections.

Why distinguish reading a property from replacing it?

Access and assignment share much of the same syntax, but they have different effects on state. Reading shape.fill observes a value; assigning shape.fill = nextColour mutates the object that other references may also see. During a trace, label the operation and record the before and after values whenever mutation is intended.

This prevents a debugging inspection from becoming an accidental edit and reveals whether later visual changes arise from reordered array positions or modified object data.

How can I verify that a collection matches its intended model?

Inspect the whole array and one representative object before writing a long access expression. Confirm that sequence matters for the collection, that every required property has the same spelling and that each value has the type expected by later geometry or colour code. Test the first and last valid indices plus the empty case. Then reorder two items and check which observations should change.

Positional results should follow the new order, while named properties should retain their meaning. That contrast is evidence that the structure represents both order and attribute identity correctly.

Study strategy

Assessment move

Draw objects as labelled property boxes and arrays as indexed rails. For nested access, evaluate the array position first, inspect the object found there and then read its property. Practise last item expressions with collections of different sizes. If an access yields undefined, split the chain into temporary values to reveal whether the index or key failed.

Working through Objects, Arrays and Property Access in IDEA9103? Sia is AskSia’s AI Computer Science tutor — ask any IDEA9103 Objects, Arrays and Property Access question and get a clear, step-by-step explanation grounded in how IDEA9103 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 202 of your University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your IDEA9103 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works