Validator.js: Check weather a data is available in a given array

Created on 15 Apr 2021  路  4Comments  路  Source: validatorjs/validator.js

Feature request

isInaArray()
Inputs :
(array,item to find in array)
input type:
(Array,item)
This function fill return true or false. This function will check weather the given item is available in the given array.
It is a kind of filter function
Code

function isInaArray(array,item){
  if(array.filter(ele=>ele == item).length>0){
     return true
}else{
    return false
}
} 
馃檵鈥嶁檪锔廸eature-request

Most helpful comment

There is already a javascript built-in Array method doing exactly what you need: Array.find

All 4 comments

There is already a javascript built-in Array method doing exactly what you need: Array.find

Array.find will return the value if the value is found on the list of items in an array. will return undefined if the value didn't found.
We need to returntrue arefalse.

[].includes(item) does the job. Alternatively you can use Array.prototype.find with double negation !![].find(item).

[].includes(item) does the job. Alternatively you can use Array.prototype.find with double negation !![].find(item).

Thanks for the replay !!Array.find(item=>item == elemnt)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mfbx9da4 picture mfbx9da4  路  4Comments

AtomicBorg picture AtomicBorg  路  3Comments

rathboma picture rathboma  路  4Comments

zilahir picture zilahir  路  3Comments

galki picture galki  路  3Comments