Search code examples
javascriptlodash

How to check whether string is present in array with lodash js?


My snippet looks something like this:

let go = "hello";

let col =["12","hello","14","15"];

let f = _.some(col,go);

I want to check whether the go value is present in col TRUE/FALSE. When I run this I get , f=false? How can I fix this or how to check the presence of a string in an array of strings (with lodash)?


Solution

  • Should work

    let go = "hello";
    
    let col =["12","hello","14","15"];
    
    let f = _.includes(col,go);
    

    https://lodash.com/docs#includes