Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var meta = {
    name: "person_list",
    type: [],
    component: [{
        name: 'black_hair',
        type: {},
        component: {
            name: 'list',
            type: []
        }
    }]
};
var myObject = {
    person_list: [{
        asdfa: {
            list: [
                'bob',
                'john',
                'allen']
        }
    }]
};
function defined(meta, obj) {
    if (meta.name == 'list' && obj[meta.name] && obj[meta.name].length) {
        return true;
    }
    if (!obj[meta.name]) {
        return false;
    };
    if (Object.prototype.toString.call(meta.type) === '[object Array]' && !obj[meta.name].length) {
        return false;
    } else if (Object.prototype.toString.call(meta.type) === '[object Array]' && obj[meta.name].length) {
        for (index in obj[meta.name]) {
            return defined(meta.component[index], obj[meta.name][index]);
        }
    } else if (Object.prototype.toString.call(meta.type) === '[object Object]') {
        return defined(meta.component, obj[meta.name]);
    }
}
console.log(defined(meta, myObject));
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers