Wednesday, August 31, 2016

Determine if the object has a property and value in javascript

One of the best and simple solution
function hasValue(obj, key, value) {
    return obj.hasOwnProperty(key) && obj[key] === value;
}
var test = [{name : "joey", age: 15}, {name: "hell", age: 12}]
console.log(test.some(function(boy) { return hasValue(boy, "age", 12); }));

Saturday, October 31, 2015

 var error;

        if (e instanceof nlobjError) {
            nlapiLogExecution('ERROR', 'system error', e.getCode() + '\n' + e.getDetails());
            error = e.getCode() + ': ' + e.getDetails();
        } else {
            nlapiLogExecution('ERROR', 'unexpected error', e.toString());
            error = e.toString();
        }