What is iterate-object?
The iterate-object npm package provides a simple utility to iterate over the properties of an object. It allows you to perform operations on each key-value pair in the object.
What are iterate-object's main functionalities?
Basic Iteration
This feature allows you to iterate over each key-value pair in an object and perform operations on them. In this example, it logs each key and value to the console.
const iterateObject = require('iterate-object');
const obj = { a: 1, b: 2, c: 3 };
iterateObject(obj, (value, key) => {
console.log(key, value);
});
Modify Object Values
This feature allows you to modify the values of the object during iteration. In this example, it multiplies each value by 2.
const iterateObject = require('iterate-object');
const obj = { a: 1, b: 2, c: 3 };
iterateObject(obj, (value, key) => {
obj[key] = value * 2;
});
console.log(obj);
Filter Object Properties
This feature allows you to filter the properties of an object based on a condition. In this example, it creates a new object with properties that have values greater than 1.
const iterateObject = require('iterate-object');
const obj = { a: 1, b: 2, c: 3 };
const filteredObj = {};
iterateObject(obj, (value, key) => {
if (value > 1) {
filteredObj[key] = value;
}
});
console.log(filteredObj);
Other packages similar to iterate-object
lodash
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes methods like _.forOwn and _.forEach for iterating over object properties. Compared to iterate-object, Lodash offers a more comprehensive set of utilities but is also larger in size.
underscore
Underscore is another utility library similar to Lodash, providing a variety of functions for working with arrays, objects, and other data types. It includes methods like _.each and _.mapObject for iterating over object properties. Like Lodash, it offers more functionality than iterate-object but is also larger.
object-foreach
object-foreach is a lightweight utility specifically designed for iterating over object properties. It provides a simple API similar to iterate-object but with fewer additional features. It is a good alternative if you need a minimalistic solution.
iterate-object


A convenient way to iterate objects.
:cloud: Installation
npm install --save iterate-object
yarn add iterate-object
:clipboard: Example
var IterateObject = require("iterate-object");
IterateObject({
name: "Bob"
, age: 42
}, function (value, name) {
console.log(name, value);
});
IterateObject([
1, 2, 3, 4, 5, 6, 7
], function (value, i) {
console.log("v[" + i + "] = " + value);
});
IterateObject([
"Alice", "Bob", "Carol", "Dave"
], function (value, i, arr) {
console.log("Current: " + value + (arr[i + 1] ? " Next:" + arr[i + 1] : ""));
});
:question: Get Help
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. :bug:
- For direct and quick help, you can use Codementor. :rocket:
:memo: Documentation
iterateObject(obj, fn)
Iterates an object. Note the object field order may differ.
Params
- Object
obj
: The input object. - Function
fn
: A function that will be called with the current value, field name and provided object.
Return
- Function The
iterateObject
function.
:yum: How to contribute
Have an idea? Found a bug? See how to contribute.
:sparkling_heart: Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like :rocket:
-
—I love books! I will remember you after years if you buy me one. :grin: :book:
-
—You can make one-time donations via PayPal. I'll probably buy a coffee tea. :tea:
-
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! :heart:
:dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:
@acegoal07/json-editor
@isysd/gpm
@rivkesse/emoji-category-map
@slikts/scrape-it
@ywzhaiqi/scrape-it-core
angularvezba
barbe
bloggify
bloggify-actions
bloggify-cli
bloggify-config
bloggify-flexible-router
bloggify-mongoose
bloggify-on-request
bloggify-page
bloggify-paths
bloggify-redirect
bloggify-sequelize
bloggify-shortcode
bloggify-template-renderer
bloggify-theme-renderer
color-it
couleurs
edit-json-file
elly
emoji-from-word
emoji-unicode-map
emoji.css
emojic
engine-builder
engine-flow-types
engine-parser
enny
err
error-creator
fixmtoacrisconverter
fixmtoacrisconverterlib
fixmtoacristransformer
gh-following
git-stats
gm-tools
gpm
html-encoder-decoder
lien
love-you
map-o
markdownalint-cli2
match
mini-lightbox
nodeice
oargv
obj-flatten
obj-unflatten
remove-one-element-arrays
rucksack
scrape-it-core
scrape-it-plus
scraped-core
stringify-env
svg.connectable.js
tilda
tools_may_24
validate5
xml-jsonify
:scroll: License
MIT © Ionică Bizău