Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Underscore.js _.mapObject() Function

  • Last Updated : 25 Nov, 2021

The _.mapObject() function is similar to the map but used for the object. This function transforms each value of the object based on the given function/operation.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

_.mapObject(object, iteratee, [context])

Parameters: This function accepts three parameters as mentioned above and described below:

  • object: It contains the object element that holds the elements of key and value pair.
  • iteratee: It is the function which is used to take all the elements of the list and it also remember all the returned value.
  • context: This parameter is used to display the content.

Return Value: It returns the transform value of each object element.



Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
            src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var res = _.mapObject({ num1: 10, num2: 15 },
            function (value, key) {
                return value * 10;
            });
  
        console.log(res);
    </script>
</body>
  
</html>

Output:

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
            src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        _.mapObject({ num1: 10, num2: 15, num3: 20, num4: 25, num5: 30 },
  
            function (value, key) {
                console.log(key + ': ' + (value + 10));
            });
    </script>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!