Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对象数组中的jQuery筛选方法是对象的内容_Jquery - Fatal编程技术网

对象数组中的jQuery筛选方法是对象的内容

对象数组中的jQuery筛选方法是对象的内容,jquery,Jquery,os.networkInterfaces()是节点webkit应用程序中用于获取客户端计算机的网络相关数据的函数。 对我的机器来说就像 我编写了一个代码来获取客户端计算机的IPv4地址,以便在我的nw.js应用程序中使用。逻辑是,;从内部为false且族为IPv4的对象中查找地址。这是代码 $.each(os.networkInterfaces(),function(key,value){ $(value).each(function(index,item){ if(i

os.networkInterfaces()是节点webkit应用程序中用于获取客户端计算机的网络相关数据的函数。 对我的机器来说就像

我编写了一个代码来获取客户端计算机的IPv4地址,以便在我的nw.js应用程序中使用。逻辑是,;从内部为false且族为IPv4的对象中查找地址。这是代码

$.each(os.networkInterfaces(),function(key,value){
    $(value).each(function(index,item){
        if(item.internal==false && item.family=='IPv4'){
            console.log(item.address); // result is "10.0.8.42" from the above picture
        }
    });
});

有没有其他方法可以做到这一点。在这种情况下,我们可以在这里应用jquery筛选方法吗?

不要使用jquery-只需使用常规的JS Array.reduce和Array.filter:

let interfaces = os.networkInterfaces()
let matchingObjects = Object.keys(interfaces).reduce(function(matches, key) {
    return matches.concat(interfaces[key].filter(function(face) {
        return face.internal === false && face.family === "IPv4"
    }).map(function(face) {
        return face.address; //just get the address
    }));
}, []);

不要使用jQuery-只需使用常规的JS Array.reduce和Array.filter:

let interfaces = os.networkInterfaces()
let matchingObjects = Object.keys(interfaces).reduce(function(matches, key) {
    return matches.concat(interfaces[key].filter(function(face) {
        return face.internal === false && face.family === "IPv4"
    }).map(function(face) {
        return face.address; //just get the address
    }));
}, []);