Syntax, Parameter and Return Value
Syntax:
_.entriesIn(object)
Parameters:
object (Object): The object to convert.
Return Value:
(Array) - Returns the array of key-value pairs.
Examples
Basic Usage with Inherited Properties:
JavaScript
var _ = require('lodash');
function Parent() {
this.parentProp = 'parent value';
}
Parent.prototype.inheritedMethod = function() {};
var child = new Parent();
child.childProp = 'child value';
console.log(_.entriesIn(child));

You can also try this code with Online Javascript Compiler
Run Code
Output:
[['parentProp', 'parent value'], ['childProp', 'child value'], ['inheritedMethod', function() {}]]
Demonstrates including both own and inherited properties in the entries array.
Iterating Over All Properties:
JavaScript
var object = Object.create({ inheritedProp: 'inherited' });
object.ownProp = 'own';
_.entriesIn(object).forEach(([key, value]) => {
console.log(`${key}: ${value}`);
});

You can also try this code with Online Javascript Compiler
Run Code
Output:
'ownProp: own', 'inheritedProp: inherited'
Shows how to iterate over all properties, including inherited ones.
Combining with Other Lodash Methods:
JavaScript
var complexObject = Object.create({ inheritedProp: 42 });
complexObject.ownProp = 100;
var formattedEntries = _.chain(complexObject)
.entriesIn()
.map(([key, value]) => `${key}: ${value}`)
.value();
console.log(formattedEntries);

You can also try this code with Online Javascript Compiler
Run Code
Output:
['ownProp: 100', 'inheritedProp: 42']
Demonstrates using _.entriesIn() in combination with other Lodash methods for custom formatting.
Processing Inherited Data:
JavaScript
function Shape() {
this.type = 'shape';
}
Shape.prototype.displayType = function() { return this.type; };
var circle = new Shape();
circle.radius = 5;
var circleEntries = _.entriesIn(circle);
console.log(circleEntries);

You can also try this code with Online Javascript Compiler
Run Code
Output:
[['type', 'shape'], ['radius', 5], ['displayType', function() {}]]
An example of processing both own and inherited properties of an object.
Frequently Asked Questions
How does _.entriesIn() differ from _.entries()?
While _.entries() (or _.toPairs()) only retrieves an object's own properties, _.entriesIn() includes both the object's own and inherited properties.
Can _.entriesIn() handle properties from deeply nested inheritance chains?
Yes, _.entriesIn() will retrieve properties from the entire prototype chain, not just the immediate parent.
Is it recommended to use _.entriesIn() for all objects?
Use _.entriesIn() when you specifically need to consider inherited properties. For many use cases, especially with plain objects, _.entries() might be more appropriate to avoid unintentional inclusion of prototype properties.
Conclusion
Lodash's _.entriesIn() method is an effective tool for converting an object into an array of its own and inherited enumerable properties as [key, value] pairs. It's especially useful in object-oriented programming and in scenarios where a comprehensive view of an object's properties, including those from its prototype chain, is required.
You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.
Also, check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.