New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

foreach-prop

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foreach-prop

Array-like methods for objects

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-90.36%
Maintainers
1
Weekly downloads
 
Created
Source

foreach-prop

CircleCI Greenkeeper badge npm codecov Known Vulnerabilities GitHub

Array-like methods for objects

Install

npm install foreach-prop

Methods

forEach

similar to Array.prototype.forEach. It executes the provided callback function for every key-value-pair in the object. Once iniciated there is no way to stop the execution of this function, if you intend to stop the iteration at some point have a look at findKey method.

forEach(object, function callback(value, key, ...extra) => void, ...extra): void;

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

forEach.call(thisArg, object, callback, ...extra);
map

similar to Array.prototype.map. It executes the provided callback function for every key-value-pair in the object and returns a new object.

map(object, function callback(value, key, ...extra) => any, ...extra): object;

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

map.call(thisArg, object, callback, ...extra);
keyOf

similar to Array.prototype.indexOf. It returns the key of the first value that equals the provided one.

keyOf(object, value): string;
lastKeyOf

similar to Array.prototype.lastIndexOf. It returns the key of the last value that equals the provided one.

lastKeyOf(object, value): string;
findKey

similar to Array.prototype.findIndex. It executes the provided callback function for every key-value-pair in the object and returns the key once the provided callback function return a truthy value. It returns null if nothing found.

findKey(object, function callback(value, key, ...extra) => any, ...extra): string;

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

findKey.call(thisArg, object, callback, ...extra);
find

similar to Array.prototype.find. It executes the provided callback function for every key-value-pair in the object and returns the value once the provided callback function return a truthy value. It returns undefined if nothing found.

find(object, function callback(value, key, ...extra) => any, ...extra): any;

Note that the returned value may be undefined even if the condition is met and the value is undefined.

const something; // something is undefined
const value = find({ something }, (val, key) => (key === "something"));
console.log(value); // it logs undefined because something is undefined

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

find.call(thisArg, object, callback, ...extra);
filter

similar to Array.prototype.filter. It executes the provided callback function for every key-value-pair in the object and returns a new object containing the key-value-pairs corresponding to those where the provided callback function returned a truthy value.

filter(object, function callback(value, key, ...extra) => any, ...extra): object;

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

filter.call(thisArg, object, callback, ...extra);
reduce

similar to Array.prototype.reduce but with a major difference: if no initial value provided it defaults to undefined.

reduce(object, function callback(current, value, key, ...extra) => any, initial, ...extra): any;

The callback function inherits the this value from the function call, so if you want a specific this value in your callback function, you can call it using the call method of the Function.prototype...

reduce.call(thisArg, object, callback, initial, ...extra);

License

MIT License

Keywords

FAQs

Package last updated on 03 May 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc