npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

isotropic-for-in

v0.13.1

Published

A function to iterate an object's enumerable own and inherited properties

Readme

isotropic-for-in

npm version License

A utility function that iterates through all enumerable properties of an object, including those inherited through the prototype chain.

Why Use This?

  • Complete Enumeration: Iterate over both own and inherited enumerable properties
  • Familiar API: Works like Array.prototype.forEach but for object properties
  • Prototype-aware: Unlike Object.keys().forEach(), includes properties from the entire prototype chain
  • Callback Parameters: Provides value, key, and object reference to the callback function
  • Zero Dependencies: Lightweight implementation with no external requirements

Installation

npm install isotropic-for-in

Usage

import _forIn from 'isotropic-for-in';

{
    // Basic usage
    const object = {
        a: 1,
        b: 2
    };

    _forIn(object, (value, key, object) => {
        console.log(`${key}: ${value}`);
    });
    // Output:
    // a: 1
    // b: 2
}

{
    // With prototype chain
    const parent = {
            x: 'inherited',
            y: 'also inherited'
        },

        child = Object.create(parent);

    child.z = 'own property';

    _forIn(child, (value, key) => {
        console.log(`${key}: ${value}`);
    });

    // Output:
    // z: own property
    // x: inherited
    // y: also inherited
}

API

forIn(object, iterationFunction)

Iterates over all enumerable properties of an object, including those in its prototype chain.

Parameters

  • object (Object): The object to iterate over.
  • iterationFunction (Function): The function to call for each property, which receives three arguments:
    • value: The property's value
    • key: The property's name
    • object: The object being iterated

Returns

  • undefined: The function doesn't return a value.

Examples

Basic Property Iteration

import _forIn from 'isotropic-for-in';

{
    const person = {
        age: 30,
        name: 'John',
        occupation: 'Developer'
    };

    forIn(person, (value, key) => {
        console.log(`${key}: ${value}`);
    });
    // Output:
    // age: 30
    // name: John
    // occupation: Developer
}

Combining with Other Utility Functions

import _forIn from 'isotropic-for-in';

const _getAllValues object => {
        // Collect all enumerable property values into an array
        const values = [];

        _forIn(object, value => {
            values.push(value);
        });

        return values;
    },

    _findProperty = (object, testFunction) => {
        // Find the first property that matches a condition
        let result = null;

        _forIn(object, (value, key) => {
            if (result === null && testFunction(value, key)) {
                result = {
                    key,
                    value
                };
            }
        });

        return result;
    };

{
    // Usage example
    const settings = {
        fontSize: 16
        theme: 'dark'
    };

    Object.setPrototypeOf(settings, {
        animations: true,
        language: 'en'
    });

    console.log(_getAllValues(settings)); // [16, 'dark', true, 'en']

    console.log(_findProperty(settings, value => typeof value === 'number' && value > 10)); // { key: 'fontSize', value: 16 }
}

Creating a Nested Property Path String

import _forIn from 'isotropic-for-in';

// Function to get a dot-notation string of all property paths
const _getPropertyPaths = (object, prefix = '') => {
  const paths = [];

    _forIn(object, (value, key) => {
        const currentPath = prefix ?
            `${prefix}.${key}` :
            key;

        // Add current path
        paths.push(currentPath);

        // Recurse for objects (avoid circular references)
        if (value && typeof value === 'object' && !Array.isArray(value)) {
            paths.push(..._getPropertyPaths(value, currentPath));
        }
    });

    return paths;
};

{
    // Example
    const config = {
        server: {
            host: 'localhost',
            port: 3000
        }
    };

    // Add some inherited properties
    Object.setPrototypeOf(config.server, {
        protocol: 'http',
        timeout: 5000
    });

    console.log(_getPropertyPaths(config));
    // Output:
    // ['server', 'server.host', 'server.port', 'server.protocol', 'server.timeout']
}

Difference from Other Methods

Compared to Object.keys().forEach()

Object.keys() only returns an object's own enumerable properties, ignoring the prototype chain:

import _forIn from 'isotropic-for-in';

{
    const parent = {
            inherited: true
        },

        child = Object.create(parent);

    child.own = 'yes';

    // Using Object.keys().forEach()
    Object.keys(child).forEach(key => console.log(key));
    // Output:
    // own

    // Using isotropic-for-in
    _forIn(child, (_, key) => console.log(key));
    // Output:
    // own
    // inherited
}

Compared to Native for...in

While isotropic-for-in uses a native for...in loop under the hood, it provides:

  1. A cleaner callback-based API similar to other JavaScript iterator methods
  2. Consistent parameter order (value, key, object) matching Array.forEach
  3. A direct reference to the object being iterated
import _forIn from 'isotropic-for-in';

// Native for...in
for (const key in object) {
  const value = object[key];
  // Do something with key and value
}

// isotropic-for-in
_forIn(object, (value, key, object) => {
  // Do something with value, key, and the original object
});

Contributing

Please refer to CONTRIBUTING.md for contribution guidelines.

Issues

If you encounter any issues, please file them at https://github.com/ibi-group/isotropic-for-in/issues