Confusion in the Map()

// var map1 = new Map();

// map1.set('a',1);
// map1.set('b',2) ;
// map1.set('c',3) ;

// console.log(map1.get('a'));
// map1.set('a', 222)
// console.log(map1.get('a'))

// console.log(map1.size)
// console.log(map1.delete('c'))

// console.log(map1)

var m = new Map() ;

m.set(('A', ['B']), ('B', ['A', 'C']), ('C', ['B']));
/* This code had been working fine with Map. Whenever, I was assigining it the values individually it was accepting 
it. But when I did it is, it is just calling the second object value.*/

// m.set('A', ['B']) ;
// m.set('B', ['A', 'C']);
// m.set('C', ['B']);

console.log(typeof(m)) // Object

console.log(m) // { ['B'] => ['A', 'C'] }

Can someone help me to understand this?

set accepts 2 parameters; a key, and a value.

   (‘A’, [‘B’]), 
   (‘B’, [‘A’, ‘C’]), 
   (‘C’, [‘B’])

Isnt going to work.
What it LOOKS like you’re trying to do is use the initializer of the Map object, which can take an array of arrays (I’m going to use excessive line breaks here to make it clear what i’m doing):

let m = new Map(
     ["A", ["B"]], 
     ["B", ["A", "C"]], 
     ["C", ["B"]]

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