Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                

// $$$$ Map $$$$ ///

const mapObj1 = new Map([
  ["a", 1],
  ["b", 2],
  ["c", 3],
  ["d", 4]
]);

const obj1 = {
  a: 1,
  b: 2,
  c: 3,
  d: 4
}

console.log(obj1.constructor) // and many more

// better preformance then plain object
mapObj1.delete('a')
mapObj1.set('a', 1)

console.log(obj1, mapObj1);


// loop through maps

for ([key, val] of mapObj1) {
  console.log(key ,val)
} 


//  Map is indexed
const itemThree = [...mapObj1][3];
console.log(itemThree);

// convert map <=> ojb
const mapObj3ToObj = Object.fromEntries(mapObj1);
console.log(mapObj3ToObj);

const objToMap = new Map(Object.entries(mapObj3ToObj));
console.log(mapObj3ToObj, objToMap);


// clone/copy map

const mapObj2 = new Map(mapObj1);
const mapObj3 = structuredClone(mapObj1);

console.log('clone:',mapObj2);
console.log('deep clone:',mapObj3);

// map specialist

mapObj1.set(['e','f'], true);
mapObj1.set(mapObj3ToObj, {a:1});
// *** can be a problem with garbage collector better to use WeakMap

console.log(mapObj1.size);

console.log(mapObj1)

// stringify Map

const originalValue = new Map([['a', 1]]);
const str = JSON.stringify(originalValue, replacer);
console.log(str);
function replacer(key, value) {
  if(value instanceof Map) {
    return {
      dataType: 'Map',
      value: Array.from(value.entries())
    };
  } else {
    return value;
  }
}

// $$$$ Set $$$$ ///

const objA = {a:1};
const a = new Set([1, 2, 3]);
const b = new Set([2, objA, 4 , objA, {a:2}]);

a.has(1);
a.add('3');
a.delete(3);

console.log(console.timeStamp());
console.timeStamp()









// const b = new Map([
//   [1, "one"],
//   [2, "two"],
//   [4, "four"],
// ]);
// console.log(a); // Set(4) {1, 2, 3, 4}

// console.log(mapObj1.get('e'), obj1.e);

              
            
!
999px

Console