![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
foreach-prop
Advanced tools
Array-like methods for objects
:warning: some javascript implementations don't respect the object key order. keep that in mind when you use
keyOf
,lastKeyOf
,findKey
andfind
methods.
npm i foreach-prop
<script src="https://cdn.jsdelivr.net/npm/foreach-prop/dist/each-prop.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/foreach-prop/dist/each-prop.umd.min.js"></script>
<script src="https://unpkg.com/foreach-prop/dist/each-prop.umd.js"></script>
import { map } from "foreach-prop";
const object = {
key1: "str",
key2: 1,
};
const result = map(object, (value, key, extra1) => {
return key + extra1;
}, " $$");
console.log(result);
{
key1: "key1 $$",
key2: "key2 $$",
}
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;
Any extra
arguments will be passed to the callback function.
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);
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;
Any extra
arguments will be passed to the callback function.
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);
Similar to Array.prototype.indexOf
. It returns the key of the first value that equals the provided one, or null
if not found.
keyOf(object, value): string | null;
Similar to Array.prototype.lastIndexOf
. It returns the key of the last value that equals the provided one, or null
if not found.
lastKeyOf(object, value): string | null;
Similar to Array.prototype.includes
. It returns whether or not a value is present in an object.
includes(object, value): boolean;
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 | null;
Any extra
arguments will be passed to the callback function.
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);
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 isundefined
.
const undef;
// undef is undefined
const object = { key1: undef };
// object.key1 is also undefined
const value = find(object, (val, key) => {
return key === "key1"
});
console.log(value);
// it logs undefined
// because undef is undefined
undefined
Any extra
arguments will be passed to the callback function.
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);
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;
Any extra
arguments will be passed to the callback function.
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);
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;
Any extra
arguments will be passed to the callback function.
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);
Similar to Array.prototype.some
. It returns whether at least one of the key-value-pairs satisfy the provided callback function.
some(object, function callback(value, key, ...extra) => any, ...extra): boolean;
Any extra
arguments will be passed to the callback function.
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
.
some.call(thisrArg, object, callback, ...extra): boolean;
Similar to Array.prototype.every
. It returns whether all key-value-pairs satisfy the provided callback function.
every(object, function callback(value, key, ...extra) => any, ...extra): boolean;
Any extra
arguments will be passed to the callback function.
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
.
every.call(thisrArg, object, callback, ...extra): boolean;
MIT © Manuel Fernández
FAQs
Array-like methods for objects
The npm package foreach-prop receives a total of 0 weekly downloads. As such, foreach-prop popularity was classified as not popular.
We found that foreach-prop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.