UNPKG

@hackplan/polaris

Version:

Shopify’s product component library

21 lines (20 loc) 506 B
import { isObject } from './isObject'; export function pluckDeep(obj, key) { if (!obj) { return null; } const keys = Object.keys(obj); for (let i = 0; i < keys.length; i++) { const currKey = keys[i]; if (currKey === key) { return obj[key]; } if (isObject(obj[currKey])) { const plucked = pluckDeep(obj[currKey], key); if (plucked) { return plucked; } } } return null; }