Thinking through objects & arrays

“The JavaScript Array object is a global object that is used in the construction of arrays; which are high-level, list-like objects.” Javascript Array documentation on MDN

During office hours with Allison she reminded me that we can have arrays of objects. This allows me to combine my 2 initial arrays that I wanted to assign to my firefly objects. After we met I revisited Coding Train videos of Data and how to parse JSON & CSV files. As well as Allison’s own notes here.

 

So instead of writing:

let noteFrequency = [261.63, 329.63, 392.00, ];
let noteName = [ “C”, “E”, “G”]; 

let fireflies = [];

and assigning each frequency and note name to each fire fly object, one at a time.

I can use:

let fireflies = [];
let noteInfo = [
{freq: 164.81, name: “E3”},
{freq: 196.00, name: “G3”},
{freq: 261.63, name: “C4”},
{freq: 329.63, name: “E4”},
{freq: 392.00, name: “G4”},
{freq: 523.25, name: “C5”},
{freq: 261.63, name: “C4”},
{freq: 329.63, name: “E4”},
{freq: 392.00, name: “G4”}];

for (let i = 0; i < 9; i++) {
let x = random(width);
let y = random(height);
let r = (12);
firefly = new Firefly(noteInfo[i]);
fireflies.push(firefly);

 

Screen Shot 2018-11-29 at 1.49.21 AM.png

I’ve also been thinking about syntax & how we access objects within objects. See the coding train example 10.3 @ 3:50

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s