Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Iterate over the own and inherited enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js
The 'for-in' npm package is a utility that allows you to iterate over the properties of an object in JavaScript. It provides a simple and efficient way to loop through object keys, even for objects that inherit properties from their prototype.
Iterating over object properties
This feature allows you to loop through each property of an object. The function provided to forIn is called with each property's value and key. This is particularly useful for objects with enumerable properties.
const forIn = require('for-in');
const object = {a: 1, b: 2, c: 3};
forIn(object, function(value, key) {
console.log(key + ': ' + value);
});
Lodash's forEach method is similar to for-in but offers more extensive functionality, such as iterating over arrays, objects, and other collection types. It also supports exiting the iteration early by returning false, which is not supported by for-in.
This is not an npm package but a built-in JavaScript method that returns an array of a given object's own enumerable string-keyed property [key, value] pairs. This can be used in combination with forEach for similar functionality to for-in but requires conversion to an array first.
Iterate over the own and inherited enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning
false
. JavaScript/Node.js
Install with npm:
$ npm install --save for-in
var forIn = require('for-in');
var obj = {a: 'foo', b: 'bar', c: 'baz'};
var values = [];
var keys = [];
forIn(obj, function (value, key, o) {
keys.push(key);
values.push(value);
});
console.log(keys);
//=> ['a', 'b', 'c'];
console.log(values);
//=> ['foo', 'bar', 'baz'];
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
16 | jonschlinkert |
2 | paulirish |
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.4.2, on February 28, 2017.
FAQs
Iterate over the own and inherited enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js
The npm package for-in receives a total of 11,883,566 weekly downloads. As such, for-in popularity was classified as popular.
We found that for-in demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.