10 examples of 'js map constructor' in JavaScript

Every line of 'js map constructor' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
73export function map(map: MapFunc) { return new Map(map); }
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7constructor(private map: Interfaces.IMap<E, boolean>) {
8}
1export default function MapCtor(entries) {
2 return Object.setPrototypeOf(new Map(entries), Object.getPrototypeOf(this))
3}
24constructor(obj: Object) {
25 super(obj);
26}
95export default function Map() {
96 let keys = [];
97 let values = [];
98
99 this.get = function getValueForKey(key) {
100 const index = keys.indexOf(key);
101 if (index === -1) {
102 return undefined;
103 }
104 return values[index];
105 };
106
107 this.set = function setValueForKey(key, value) {
108 const index = keys.indexOf(key);
109 if (index === -1) {
110 keys.push(key);
111 values.push(value);
112 } else {
113 values[index] = value;
114 }
115 };
116
117 this.delete = function deleteKey(key) {
118 const index = keys.indexOf(key);
119 if (index !== -1) {
120 keys.splice(index, 1);
121 values.splice(index, 1);
122 }
123 };
124
125 this.clear = function clear() {
126 keys = [];
127 values = [];
128 };
129
130 this.forEach = function(callback, context) {
131 for (let i = 0; i < keys.length; i++) {
132 if (context) {
133 callback.call(context, values[i], keys[i]);
134 } else {
135 callback(values[i], keys[i]);
136 }
137 }
138 };
139}
75constructor(iterable = undefined) {
76 if (!isObject(this))
77 throw new TypeError('Map called on incompatible type');
78
79 if (hasOwnProperty.call(this, 'entries_')) {
80 throw new TypeError('Map can not be reentrantly initialised');
81 }
82
83 initMap(this);
84
85 if (iterable !== null && iterable !== undefined) {
86 for (var [key, value] of iterable) {
87 this.set(key, value);
88 }
89 }
90}
33constructor () {
34 this._rootMap = new FlimsyMap()
35}
93function createMap() {
94 if( Map !== void 0 ) {
95 return new Map();
96 }
97 else {
98 return new ObjectMap();
99 }
100}
153constructor(iterable?: ArrayLike<[K, V]>) {
154 if (!(this instanceof Map)) {
155 throw new TypeError('Constructor Map requires "new"');
156 }
157
158 if (iterable) {
159 // Can't depend on iterable protocol yet. Don't use
160 // forEach so this works with array like objects too.
161 for (let i = 0; i < iterable.length; i++) {
162 this.set(iterable[i][0], iterable[i][1]);
163 }
164 }
165}
14constructor(keys, values) {
15 this.keys = keys;
16 this.values = values;
17}

Related snippets