Is this an array? An object without key:value pairs?

Tell us what’s happening:
Describe your issue in detail here.
My question pertains to the structure choice for ‘dictionary’ in the constructor & the example code (i.e. ’ const set1 = new Set([1, 2, 3, 5, 5, 2, 0]); )

Beau used an array at that site & that makes sense but on FCC an object is being used to store an array. My question and confusion is this:

If an object is key:value pairs then what is the example code ‘set1’? Is it a neither an array or object but a prototype? (i.e. ‘// output: {1, 2, 3, 5, 0}’<-?)

  **Your code so far**

class Set {
constructor() {
  // Dictionary will hold the items of our set
  this.dictionary = {};
  this.length = 0;

// This method will check for the presence of an element and return true or false
has(element) {
  return this.dictionary[element] !== undefined;

// This method will return all the values in the set
values() {
  return Object.values(this.dictionary);

// Only change code below this line
add(element) {
  let firstSet = values();
  if(firstSet.indexOf(element) === -1){
    return true;
  return false;

remove(element) {
  let firstSet = values();
  const index = values().indexOf(element);
  if(index !== -1){
  values().splice(index, 1)
  return true;
  return false;
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36

Challenge: Create a Set Class

Link to the challenge:

What makes you think it is using an object to store an array? It is using an object to store data in a data structure called a “set”, which is similar to an array but all values are unique. JS has a built in Set data structure, but this is trying to build its own from scratch. One uses an array to accomplish that, the other is trying to use an object.

If an object is key:value pairs then what is the example code ‘set1’?

It is an object, an instance of the class Set.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.