@alexaivars/get-in

Get a value from object by path

Usage no npm install needed!

<script type="module">
  import alexaivarsGetIn from 'https://cdn.skypack.dev/@alexaivars/get-in';
</script>

README

getIn codecov npm version CircleCI

Get a value from object by path. Path can be a number string or array. When any value in a path is undefined then getIn will return undefined or defaultValue if this is provided.

Installation

yarn add @alexaivars/get-in

Usage

const getIn = require("@alexaivars/get-in");
const context = {
  foo: {
    bar: {
      baz: "waldo"
    }
  }
};

console.log(getIn(context, ["foo", "bar", "baz"])); // waldo
console.log(getIn(context, ["foo", "quux"])); // undefined
console.log(getIn(context, ["foo", "quux"], "notSetValue")); // "notSetValue"

Tests

yarn test