Google News
logo
Lodash Interview Questions
The _.startsWith() function determines if the string starts with the specified string. The _.endsWith() function determines if the string ends with the specified string.
Example :
<!DOCTYPE html>
<html>
<head>
    <title>Lodash Tutorial</title>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>

    <script type="text/javascript">
  const words = ["tank", "boy", "tourist", "ten",
    "pen", "car", "marble", "sonnet", "pleasant",
    "ink", "atom"]

  console.log("Starting with 't'");
  words.forEach( e => {

   if (_.startsWith(e, 't')) {

    console.log(e);
   }
  });

  console.log("Ending with 'k'");
  words.forEach( e => {

   if (_.endsWith(e, 'k')) {

    console.log(e);
   }
  });
    </script>
</head>
<body></body>
</html>
Output :
Starting with 't'
tank
tourist
ten
Ending with 'k'
tank
ink
The _.keys() function returns an array of the property names of the JavaScript object and the _.values() function returns an array of their values.
Example :
<!DOCTYPE html>
<html>
<head>
    <title>Lodash Tutorial</title>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>

    <script type="text/javascript">
        // using Object Literals
        var user = {
            firstName: 'FreeTime',
            lastName: 'Learn',
            emailId: 'freetimelearn@gmail.com',
            age: 31,
            getFullName: function () {
                return user.firstName + " " + user.lastName;
            }
        }

        const keys = _.keys(user);
        console.log(keys);

        const values = _.values(user);
        console.log(values);
    </script>
</head>
<body></body>
</html>
Output :

Lodash
The _.forIn() function can be used to iterate over object properties.
Example :
<!DOCTYPE html>
<html>
<head>
    <title>Lodash Tutorial</title>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>

    <script type="text/javascript">
        // using Object Literals
        var user = {
            firstName: 'Free Time',
            lastName: 'Learning',
            emailId: 'info@freetimelearning.com',
            age: 31
        }

        _.forIn(user, (value, key) => {
            console.log(`${key}: ${value}`);
        })
    </script>
</head>
<body></body>
</html>
Output :

Lodash iterate object properties
* Lodash _.add() Method

*
Lodash _.ceil() Method

*
Lodash _.divide() Method

*
Lodash _.floor() Method

*
Lodash _.max() Method

*
Lodash _.maxBy() Method

*
Lodash _.mean() Method

*
Lodash _.meanBy() Method

*
Lodash _.min() Method

*
Lodash _.minBy() Method

*
Lodash _.multiply() Method

*
Lodash _.round() Method

*
Lodash _.subtract() Method

*
Lodash _.sum() Method

*
Lodash _.sumBy() Method

Refernces : Lodash, Lodash Doc