Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

date: guided notes: arrays arrays - an array is a _______________ data …

Question

date:
guided notes: arrays
arrays

  • an array is a _______________ data type that is used to store similar data values.
  • an ____________ is like the page number for a value in an array.
  • the count for an index always _______________.
  • example: label the indices of the array: \twizzlers\, \m&ms\, \sour patch kids\, \haribo\
  • to access data in an array, we use _______________
  • example: use arraynameindex to change \m&ms\ to

erds\ in the candy array above.

length & adding values

  • the __________ property calculates the _____________ in an array.
  • ____________ hard - coding the next available position by using the length property.
  • the array.push() function adds a value _______________ of an array.
  • example: names.push(\john\) will add __________ to the ______ array.
  • array.push() is a special kind of function called a ____________.
  • a __________ is a function that is _____________ of data and

is built into the data type.
© 2023 operation spark

Explanation:

Brief Explanations
Arrays Section:
  • An array is a composite (or "structured") data type that is used to store similar data values. (Arrays group multiple values, so they’re composite/structured.)
  • An index is like the page number for a value in an array. (Indices identify the position of elements in an array.)
  • The count for an index always starts at 0 (in most programming languages like JavaScript, Python lists use 0-based indexing by default here; the example array has 4 elements, indices 0,1,2,3).
  • Example: For ["Twizzlers", "M&Ms", "Sour Patch Kids", "Haribo"], indices are 0: Twizzlers, 1: M&Ms, 2: Sour Patch Kids, 3: Haribo.
  • To access data in an array, we use arrayName[index] (the syntax to reference an element by its index).
Length & Adding Values Section:
  • The length property calculates the number of elements in an array. (In JavaScript, array.length gives the count of elements.)
  • Avoid hard - coding the next available position by using the .length property. (Using length is better than manually typing the index, e.g., array[array.length] to add to the end instead of array[3] if you know the length is 4.)
  • The array.push() function adds a value to the end of an array.
  • Example: names.push("John") will add "John" to the names array.
  • array.push() is a special kind of function called a method.
  • A method is a function that is associated with an object (arrays are objects in JavaScript, and methods are functions defined on the object’s prototype) of data and is built into the data type.

Answer:

Arrays Section:
  • An array is a \(\boldsymbol{\text{composite (structured)}}\) data type that is used to store similar data values.
  • An \(\boldsymbol{\text{index}}\) is like the page number for a value in an array.
  • The count for an index always \(\boldsymbol{\text{starts at 0}}\).
  • Example indices: \(0\): Twizzlers, \(1\): M&Ms, \(2\): Sour Patch Kids, \(3\): Haribo.
  • To access data in an array, we use \(\boldsymbol{\text{arrayName[index]}}\).
Length & Adding Values Section:
  • The \(\boldsymbol{\text{length}}\) property calculates the \(\boldsymbol{\text{number of elements}}\) in an array.
  • \(\boldsymbol{\text{Avoid}}\) hard - coding the next available position by using the .length property.
  • The array.push() function adds a value \(\boldsymbol{\text{to the end}}\) of an array.
  • Example: names.push("John") will add \(\boldsymbol{\text{"John"}}\) to the \(\boldsymbol{\text{names}}\) array.
  • array.push() is a special kind of function called a \(\boldsymbol{\text{method}}\).
  • A \(\boldsymbol{\text{method}}\) is a function that is \(\boldsymbol{\text{associated with an object}}\) of data and is built into the data type.