Home » JavaScript Map set() Method

JavaScript Map set() Method

by Online Tutorials Library

JavaScript Map set() method

The JavaScript map set() method is used to add or updates an element to map object with the particular key-value pair. Each value must have a unique key.

Syntax

The set() method is represented by the following syntax:

Parameter

key – It represents the key to be added.

value – It represents the value to be added.

Return

The Map object.

JavaScript Map set() method example

Here, we will understand set() method through various examples.

Example 1

Let’s see an example to add key and value pair of elements to map object.

Test it Now

Output:

jQuery  AngularJS  Bootstrap  

Example 2

In this example, we will determine the result when same key is added with different values.

Test it Now

Output:

AngularJS  undefined  Bootstrap  

Next TopicJavaScript Map

You may also like