If all these things are True Run the function
if ((obj instanceof Object) &&
(Array.isArray(obj[key])) &&
(obj.hasOwnProperty(key)) &&
(obj[key].length !== 0)) {
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
if (obj instanceof Object && obj[key] instanceof Array && obj[key] != []) {};
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
Array.isArray([1, 2, 3])
var animals = ['tapir','giraffe', 'ostrich']
Array.isArray(animals)
var a;
a = 123;
console.log(typeof a); // 'number'
a = "text string";
console.log(typeof a); // 'string'
a = [];
console.log(typeof a); // 'object'
a = {};
console.log(typeof a); // 'object'
a = true;
console.log(typeof a); // 'boolean'
a = null;
console.log(typeof a); // 'object'
a = undefined;
console.log(typeof a); // 'undefined'
a = function(){};
console.log(typeof a); // 'function'
a = new Date();
console.log(typeof a); // 'object'
You can just check if the variable has a truthy value or not. That means
if( value ) {
}
will evaluate to true if value is not:
null
undefined
NaN
empty string ("")
0
false
var obj = {
first: "John",
last: "Doe"
};
// Visit non-inherited enumerable keys
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Properties are the values associated with a JavaScript object. A JavaScript object is a collection of unordered properties. Properties can usually be changed, added, and deleted, but some are read only.