How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 12-02-create-set-from-data.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js file that defines a main function with an array of string. Create a new set with that array as a constructor argument:
// main.js 
export function main() { 
  const rockets = [ 
    'US: Saturn V', 
    'US: Falcon Heavy', 
    'USSR: Soyuz', 
    'CN: Long March', 
    'US: Saturn V', 
    'US: Saturn V' 
  ];
 
  const rocketSet = new Set(rockets); 
  console.log(rockets); 
}  
  1. Start your Python web server, and the following URL in your browser: http://localhost:8000/.
  1. You should see the following output:

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.