Answers for "javascript find in array cannot read property of undefined"

0

javascript find in array cannot read property of undefined

function getSafe(fn, defaultVal) {
  try {
    return fn();
  } catch (e) {
    return defaultVal;
  }
}

// use it like this
console.log(getSafe(() => obj.a.lot.of.properties));

// or add an optional default value
console.log(getSafe(() => obj.a.lot.of.properties, 'nothing'));
 Run code snippet
Posted by: Guest on March-09-2022

Code answers related to "javascript find in array cannot read property of undefined"

Code answers related to "Javascript"

Browse Popular Code Answers by Language