Node.js determines whether the element contains

In Node.js, you can use the Array.prototype.some() method to determine whether an array contains an element. Here is a sample code:

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); // Output true
In the above code, we used the Array.prototype.some() method to traverse each element in the array, and use the JSON.stringify() method to convert each element Compare strings. Returns true if an element equal to the element being checked is found, false otherwise.

Guess you like

Origin blog.csdn.net/qq_42015021/article/details/132041465