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;
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
add a comment |
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
hello
andjames
should both be in the string to be true?
– Eddie
Mar 25 at 4:13
@Eddie more like or so in pseudo codestring.includes('hello' || 'james');
– Smokey Dawson
Mar 25 at 4:14
add a comment |
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
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
javascript
edited Mar 25 at 4:23
Smokey Dawson
asked Mar 25 at 4:11
Smokey DawsonSmokey Dawson
1,94811855
1,94811855
hello
andjames
should both be in the string to be true?
– Eddie
Mar 25 at 4:13
@Eddie more like or so in pseudo codestring.includes('hello' || 'james');
– Smokey Dawson
Mar 25 at 4:14
add a comment |
hello
andjames
should both be in the string to be true?
– Eddie
Mar 25 at 4:13
@Eddie more like or so in pseudo codestring.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
add a comment |
2 Answers
2
active
oldest
votes
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);
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
add a comment |
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"
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
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
add a comment |
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);
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
add a comment |
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);
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);
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
add a comment |
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
add a comment |
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"
add a comment |
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"
add a comment |
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"
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"
answered Mar 25 at 4:26
Swanky CoderSwanky Coder
316212
316212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
hello
andjames
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