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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현