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:
edit-json-file
scrape-it
err
tilda
emojic
couleurs
lien
oargv
map-o
html-encoder-decoder
emoji-name-map
elly
barbe
color-it
obj-flatten
xml-jsonify
emoji-unicode-map
emoji-from-word
bloggify-template-renderer
bloggify-page
match
error-creator
obj-unflatten
bloggify-redirect
bloggify-actions
rucksack
bloggify-flexible-router
git-stats
@rivkesse/emoji-category-map
bloggify-config
svg.connectable.js
engine-parser
engine-builder
enny
engine-flow-types
mini-lightbox
nodeice
bloggify-mongoose
gm-tools
bloggify-shortcode
bloggify-paths
stringify-env
bloggify-theme-renderer
bloggify-on-request
scrape-it-plus
@slikts/scrape-it
love-you
remove-one-element-arrays
validate5
bloggify-sequelize
@isysd/gpm
emoji.css
gpm
gh-following
:scroll: License
MIT © Ionică Bizău