skip to Main Content

Incorrect answers with [] and set&get of javascript map

I was amazed by the following code in javascript var mp1 = new Map(); mp1[1] = 'apple'; mp1[2] = 'bat'; console.log(mp1.size); console.log(mp1.set(1, 'test')); console.log('using get', mp1.get(1)); console.log('using[]', mp1[1]) console.log('------------'); var mp2 = new Map(); mp2.set(1, 'match'); mp2.set(2, 'testing'); console.log(mp2.size); console.log('using…

VIEW QUESTION
Back To Top
Search