The _.keys() function returns an array of the property names of the JavaScript object and the _.values() function returns an array of their values.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Lodash _.keys() and _.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: 'Ramesh',
lastName: 'Fadatare',
emailId: 'ramesh@gmail.com',
age: 29,
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:
["firstName", "lastName", "emailId", "age", "getFullName"]
["Ramesh", "Fadatare", "ramesh@gmail.com", 29, ƒ]
Comments
Post a Comment