pass array to includes() javascriptHow do JavaScript closures work?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Why are almost all the people in this orchestra recording wearing headphones with one ear on and one ear off?

When is the phrase "j'ai bon" used?

What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?

What is this plant I saw for sale at a Romanian farmer's market?

Co-worker is now managing my team. Does this mean that I'm being demoted?

Having some issue with notation in a Hilbert space

How to ask if I can mow my neighbor's lawn

Why can't I craft scaffolding in Minecraft 1.14?

How do I run a script as sudo at boot time on Ubuntu 18.04 Server?

Lead the way to this Literary Knight to its final “DESTINATION”

Can a non-invertible function be inverted by returning a set of all possible solutions?

Why can't we feel the Earth's revolution?

Redirecting output only on a successful command call

How useful is the GRE Exam?

Are there any super-powered aliens in the Marvel universe?

The instant an accelerating object has zero speed, is it speeding up, slowing down, or neither?

Leveraging cash for buying car

High-end PC graphics circa 1990?

Would a 7805 5v regulator drain a 9v battery?

Basic power tool set for Home repair and simple projects

First occurrence in the Sixers sequence

Background for black and white chart

Is there any effect in D&D 5e that cannot be undone?

Fill the maze with a wall-following Snake until it gets stuck



pass array to includes() javascript


How do JavaScript closures work?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to find out if a string includes multiple strings stored in array with .includes()



So I've tried



let string = 'hello james';

console.log(string.includes(['hello', 'james']));


but it is being returned as false.. when I know the string includes 'hello' or 'james' is this even possible?? how can I tell if a string contains either the word 'hello' or 'james'



So in pseudo code this would look like string.includes('hello' || 'james');










share|improve this question
























  • hello and james should both be in the string to be true?

    – Eddie
    Mar 25 at 4:13











  • @Eddie more like or so in pseudo code string.includes('hello' || 'james');

    – Smokey Dawson
    Mar 25 at 4:14

















1















I'm trying to find out if a string includes multiple strings stored in array with .includes()



So I've tried



let string = 'hello james';

console.log(string.includes(['hello', 'james']));


but it is being returned as false.. when I know the string includes 'hello' or 'james' is this even possible?? how can I tell if a string contains either the word 'hello' or 'james'



So in pseudo code this would look like string.includes('hello' || 'james');










share|improve this question
























  • hello and james should both be in the string to be true?

    – Eddie
    Mar 25 at 4:13











  • @Eddie more like or so in pseudo code string.includes('hello' || 'james');

    – Smokey Dawson
    Mar 25 at 4:14













1












1








1








I'm trying to find out if a string includes multiple strings stored in array with .includes()



So I've tried



let string = 'hello james';

console.log(string.includes(['hello', 'james']));


but it is being returned as false.. when I know the string includes 'hello' or 'james' is this even possible?? how can I tell if a string contains either the word 'hello' or 'james'



So in pseudo code this would look like string.includes('hello' || 'james');










share|improve this question
















I'm trying to find out if a string includes multiple strings stored in array with .includes()



So I've tried



let string = 'hello james';

console.log(string.includes(['hello', 'james']));


but it is being returned as false.. when I know the string includes 'hello' or 'james' is this even possible?? how can I tell if a string contains either the word 'hello' or 'james'



So in pseudo code this would look like string.includes('hello' || 'james');







javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 4:23







Smokey Dawson

















asked Mar 25 at 4:11









Smokey DawsonSmokey Dawson

1,94811855




1,94811855












  • hello and james should both be in the string to be true?

    – Eddie
    Mar 25 at 4:13











  • @Eddie more like or so in pseudo code string.includes('hello' || 'james');

    – Smokey Dawson
    Mar 25 at 4:14

















  • hello and james should both be in the string to be true?

    – Eddie
    Mar 25 at 4:13











  • @Eddie more like or so in pseudo code string.includes('hello' || 'james');

    – Smokey Dawson
    Mar 25 at 4:14
















hello and james should both be in the string to be true?

– Eddie
Mar 25 at 4:13





hello and james should both be in the string to be true?

– Eddie
Mar 25 at 4:13













@Eddie more like or so in pseudo code string.includes('hello' || 'james');

– Smokey Dawson
Mar 25 at 4:14





@Eddie more like or so in pseudo code string.includes('hello' || 'james');

– Smokey Dawson
Mar 25 at 4:14












2 Answers
2






active

oldest

votes


















3














Based on the docs, includes first parameter is a string and not an array.



You can do:



If you want to check if each and every string in the array is present on the string, you can use every and includes combo






let string = 'hello james';
let toCheck = ['hello', 'james'];

let result = toCheck.every(o => string.includes(o));

console.log(result);





You can use some instead of every if you want to check at least one entry in the array is present on the string.






let string = 'hello james';
let toCheck = ['hello', 'james1'];

let result = toCheck.some(o => string.includes(o));

console.log(result);








share|improve this answer




















  • 1





    Yes thank you this is what I was looking for

    – Smokey Dawson
    Mar 25 at 4:19






  • 2





    Beat me to it :|

    – Aditya Gupta
    Mar 25 at 4:23


















0














According to the documentation, the str.includes takes a string as the first parameter.



So when you pass an array instead, it converts the array of strings to a single string, and uses that string as the first parameter of the includes function.



Just to demonstrate this point,



let string = "hello,james";
var array = ["hello", "james"]

console.log(string.includes(array)); // returns true, as array would be converted to "hello,james"






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331172%2fpass-array-to-includes-javascript%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Based on the docs, includes first parameter is a string and not an array.



    You can do:



    If you want to check if each and every string in the array is present on the string, you can use every and includes combo






    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    You can use some instead of every if you want to check at least one entry in the array is present on the string.






    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);








    share|improve this answer




















    • 1





      Yes thank you this is what I was looking for

      – Smokey Dawson
      Mar 25 at 4:19






    • 2





      Beat me to it :|

      – Aditya Gupta
      Mar 25 at 4:23















    3














    Based on the docs, includes first parameter is a string and not an array.



    You can do:



    If you want to check if each and every string in the array is present on the string, you can use every and includes combo






    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    You can use some instead of every if you want to check at least one entry in the array is present on the string.






    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);








    share|improve this answer




















    • 1





      Yes thank you this is what I was looking for

      – Smokey Dawson
      Mar 25 at 4:19






    • 2





      Beat me to it :|

      – Aditya Gupta
      Mar 25 at 4:23













    3












    3








    3







    Based on the docs, includes first parameter is a string and not an array.



    You can do:



    If you want to check if each and every string in the array is present on the string, you can use every and includes combo






    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    You can use some instead of every if you want to check at least one entry in the array is present on the string.






    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);








    share|improve this answer















    Based on the docs, includes first parameter is a string and not an array.



    You can do:



    If you want to check if each and every string in the array is present on the string, you can use every and includes combo






    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    You can use some instead of every if you want to check at least one entry in the array is present on the string.






    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);








    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    let string = 'hello james';
    let toCheck = ['hello', 'james'];

    let result = toCheck.every(o => string.includes(o));

    console.log(result);





    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);





    let string = 'hello james';
    let toCheck = ['hello', 'james1'];

    let result = toCheck.some(o => string.includes(o));

    console.log(result);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 25 at 4:19

























    answered Mar 25 at 4:17









    EddieEddie

    22.8k51942




    22.8k51942







    • 1





      Yes thank you this is what I was looking for

      – Smokey Dawson
      Mar 25 at 4:19






    • 2





      Beat me to it :|

      – Aditya Gupta
      Mar 25 at 4:23












    • 1





      Yes thank you this is what I was looking for

      – Smokey Dawson
      Mar 25 at 4:19






    • 2





      Beat me to it :|

      – Aditya Gupta
      Mar 25 at 4:23







    1




    1





    Yes thank you this is what I was looking for

    – Smokey Dawson
    Mar 25 at 4:19





    Yes thank you this is what I was looking for

    – Smokey Dawson
    Mar 25 at 4:19




    2




    2





    Beat me to it :|

    – Aditya Gupta
    Mar 25 at 4:23





    Beat me to it :|

    – Aditya Gupta
    Mar 25 at 4:23













    0














    According to the documentation, the str.includes takes a string as the first parameter.



    So when you pass an array instead, it converts the array of strings to a single string, and uses that string as the first parameter of the includes function.



    Just to demonstrate this point,



    let string = "hello,james";
    var array = ["hello", "james"]

    console.log(string.includes(array)); // returns true, as array would be converted to "hello,james"






    share|improve this answer



























      0














      According to the documentation, the str.includes takes a string as the first parameter.



      So when you pass an array instead, it converts the array of strings to a single string, and uses that string as the first parameter of the includes function.



      Just to demonstrate this point,



      let string = "hello,james";
      var array = ["hello", "james"]

      console.log(string.includes(array)); // returns true, as array would be converted to "hello,james"






      share|improve this answer

























        0












        0








        0







        According to the documentation, the str.includes takes a string as the first parameter.



        So when you pass an array instead, it converts the array of strings to a single string, and uses that string as the first parameter of the includes function.



        Just to demonstrate this point,



        let string = "hello,james";
        var array = ["hello", "james"]

        console.log(string.includes(array)); // returns true, as array would be converted to "hello,james"






        share|improve this answer













        According to the documentation, the str.includes takes a string as the first parameter.



        So when you pass an array instead, it converts the array of strings to a single string, and uses that string as the first parameter of the includes function.



        Just to demonstrate this point,



        let string = "hello,james";
        var array = ["hello", "james"]

        console.log(string.includes(array)); // returns true, as array would be converted to "hello,james"







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 4:26









        Swanky CoderSwanky Coder

        316212




        316212



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331172%2fpass-array-to-includes-javascript%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript