DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
      • can-util/dom
      • can-util/js
        • ./assign/
        • ./base-url/
        • ./cid/
        • ./deep-assign/
        • ./defaults/
        • ./deparam/
        • ./diff/
        • ./diff-object/
        • ./each/
        • ./global/
        • ./import/
        • ./is-array-like/
        • ./is-browser-window/
        • ./is-empty-object/
        • ./is-function
        • ./is-node/
        • ./is-plain-object/
        • ./is-promise/
        • ./is-promise-like/
        • ./is-string/
        • ./is-web-worker/
        • ./join-uris/
        • ./make-array/
        • ./make-promise/
        • ./param/
        • ./set-immediate/
        • ./string/
          • string.camelize
          • string.capitalize
          • string.esc
          • string.getObject
          • string.hyphenate
          • string.strReplacer
          • string.strUndHash
          • string.sub
          • string.underscore
        • ./string-to-any/
        • ./types/
    • can-view-callbacks
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-util
  • /
  • can-util/js
  • /
  • ./string/
  • /
  • string.getObject
  • / On this page
    • string.getObject

      function
      • source

      string.getObject(name, roots)

      Parameters

      1. name {String}:

        a String of dot-separated keys, representing a path of properties

      2. roots {Object|Array}:

        the object to use as the root for property based navigation

      Returns

      {*}:

      the value at the property path descending from roots

      Return the result of descending the path name through the properties of the object or objects roots

      If roots is an Array, each element of the array is evaluated, in order, until the path is found in an element's properties (and properties-of-properties, etc.). Otherwise roots is evaluated as the root object, returning either the object at the property path descended from roots or undefined if any subpath is not found.

      A path is a dot-delimited sequence of zero or more property names, such that "foo.bar" means "the property 'bar' of the object at the property 'foo' of the root." An empty path returns the first object in roots if it's an array, roots itself otherwise.

      var string = require("can-util/js/string/string");
      console.log(string.getObject("a.b.c", {a: {b: {c: "foo"}}})); // -> "foo"
      console.log(string.getObject("a.b.c", {a: {}})); // -> undefined
      console.log(string.getObject("a.b", [{a: {}}, {a: {b: "bar"}}])); // -> "bar"
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.