Search code examples
javascriptarrayslodash

Why is lodash some not working here as I expect?


I have an array

arr = ["jenny", "lucy", "jason"]

I do

_.some(arr, "jenny")

and it throws false


Solution

  • In your case (an array) the predicate must be a function to check the values.

    var arr = ["jenny", "lucy", "jason"]
    var result = _.some(arr, (x) => x === "jenny");
    
    console.log(result);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>

    Resource