You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
326 B

4 years ago
  1. 'use strict';
  2. /**
  3. * Get value of a nested property
  4. *
  5. * @param mainObject
  6. * @param key
  7. * @returns {*}
  8. */
  9. module.exports = function nestedValue(mainObject, key) {
  10. try {
  11. return key.split('.').reduce(function (obj, property) {
  12. return obj[property];
  13. }, mainObject);
  14. } catch (err) {
  15. return null;
  16. }
  17. };