Js Data Structures Objects Lab

Problem Statement

We covered the concepts of Objects in JavaScript. Now it's time to put the concepts into practice.

Learning Goals

  • Create Objects
  • Perform operations on Objects


Follow the steps below, running learn as you go to get additional information from the tests. To start, define a driver variable and assign it to an Object. Various updates will be applied to this variable (destructively and non-destructively) in this lab.

You'll be writing four functions:

  • updateDriverWithKeyAndValue()- this function should take in three arguments: a driver Object, a key and a value. This function should not mutate the driver and should return a new driver that has an updated value for the key passed in.
  • destructivelyUpdateDriverWithKeyAndValue() - this function should work the same as updateDriverWithKeyAndValue() but it should mutate the driver parameter passed in.
  • deleteFromDriverByKey() - this function should take in a driver Object and a key. It should delete the key/value pair for the key that was passed in from the driver Object. This should all not actually mutate the driver passed in.
  • destructivelyDeleteFromDriverByKey() - this function should work the same as deleteFromDriverByKey() but it should mutate the driver passed in. Be sure to consider whether and how using dot notation vs. bracket notation might affect your solution.

HINT: You might find deleteFromDriverByKey() to be a bit hard to write non-destructively. Think about how we learned to use Object.assign(). What happens if we do this:

const obj = { foo: "bar" };

const newObj = Object.assign({}, obj);

// => { foo: "bar" }

delete newObj['foo'];
// => true

// => {}

// => { foo: "bar" }

Something to keep in mind!


In this lab, we worked with creating Objects and performing operations on them.


Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us