node.js判断元素是否包括

在Node.js中,可以使用Array.prototype.some()方法来判断数组中是否包含某个元素。下面是一个示例代码:

const arr = [
{ ‘@_android:name’: ‘com.eg.android.AlipayGphone’ },
{ ‘@_android:name’: ‘com.eg.android.AlipayGphoneRC’ },
{ ‘@_android:name’: ‘hk.alipay.wallet’ }
];

const elementToCheck = { ‘@_android:name’: ‘com.eg.android.AlipayGphone’ };

const isElementIncluded = arr.some(item => JSON.stringify(item) === JSON.stringify(elementToCheck));

console.log(isElementIncluded); // 输出 true
在上面的代码中,我们使用了Array.prototype.some()方法来遍历数组中的每个元素,并使用JSON.stringify()方法将每个元素转换为字符串进行比较。如果找到了与要检查的元素相等的元素,则返回true,否则返回false。

猜你喜欢

转载自blog.csdn.net/qq_42015021/article/details/132041465