lodash._pickbyarray - Internal Pick By Array Function (v3)

3.0.2 · abandoned · verified Tue Apr 21

This package exports `pickByArray`, an internal utility function from the Lodash version 3.x series, specifically `3.0.2`. It was part of a modular build strategy that offered individual Lodash functions as standalone CommonJS modules. This specific function (`_pickByArray`) was an internal helper primarily used by other Lodash methods like `_.pick` and `_.omit` when an array of property names was provided, often with an optional predicate applied to those selected keys. It is distinct from the public `_.pickBy` function, which filters an object's properties based on a predicate applied to all its own enumerable properties. The package has not been updated since the Lodash v3 era (published around January 2015). Modern Lodash (v4.x and above, with current stable version 4.18.1) integrates such functions directly into its core, and its modular `lodash-es` build offers full tree-shaking support, negating the need for these granular, unmaintained internal modules. Developers are strongly advised to use the actively maintained `lodash` or `lodash-es` package and its public APIs.

Common errors

Warnings

Install

Imports

Quickstart

Shows how to use the legacy CommonJS `lodash._pickbyarray` module and contrasts its internal usage with the modern, public `_.pickBy` from the main Lodash package.

// This example demonstrates the usage of the legacy lodash._pickbyarray module (v3.x).
// This internal utility was designed for specific use cases within the Lodash core
// when an array of keys needed to be processed and optionally filtered.
// For general object filtering based on a predicate, use the public _.pickBy from the main 'lodash' package (v4.x+).

const pickByArray = require('lodash._pickbyarray');

const sourceObject = {
  id: 1,
  name: 'Widget',
  price: 9.99,
  category: 'Electronics',
  stock: 150
};

// Simulate an array of keys that might be selected by another internal Lodash process.
const keysToConsider = ['name', 'price', 'stock', 'nonExistentKey'];

// Use pickByArray: it typically takes the object, an array of keys to process,
// and an optional iteratee/predicate applied to values of those specific keys.
const pickedSubset = pickByArray(sourceObject, keysToConsider, (value, key) => {
  // This predicate filters *among the provided keys*.
  // Only pick keys where the value is a number and greater than 10.
  return typeof value === 'number' && value > 10;
});

console.log('Original object:', sourceObject);
console.log('Keys considered by internal logic:', keysToConsider);
console.log('Result using legacy lodash._pickbyarray (filtered subset):', pickedSubset);
// Expected output: { stock: 150 } (as 9.99 is not > 10)

// For comparison, using the modern, public `_.pickBy` from the main Lodash library:
const _ = require('lodash'); // Using require for consistency with the example, but import { pickBy } from 'lodash-es' is preferred for ESM
const publicPickByResult = _.pickBy(sourceObject, (value) => {
  // `_.pickBy` filters the entire object based on the predicate.
  return typeof value === 'number' && value > 10;
});
console.log('Result using modern _.pickBy (entire object filtered):', publicPickByResult);
// Expected output: { stock: 150 }

view raw JSON →