match() vs includes() in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

match() vs includes() in JavaScript

To me match and includes seems same . Is it really same thing? If no, then what is the difference between this 2.

19th Nov 2019, 8:59 AM
[B.S.] BITTU
[B.S.] BITTU - avatar
6 Answers
+ 3
The includes() method determines whether one string may be found within another string, returning true or false as appropriate. The match() method retrieves the result of matching a string against a regular expression and returns an array. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
19th Nov 2019, 9:52 AM
ODLNT
ODLNT - avatar
+ 1
Thanks for the answer 😊
19th Nov 2019, 9:56 AM
[B.S.] BITTU
[B.S.] BITTU - avatar
+ 1
No problem, Im glad I could help.
19th Nov 2019, 9:57 AM
ODLNT
ODLNT - avatar
+ 1
I think you also need to be careful because they handle regular expressions differently (e.g. with match you'll need to escape special RegEx characters).
21st Oct 2020, 10:35 PM
Taylor
0
Includes returns a boolean value right?
19th Nov 2019, 9:53 AM
[B.S.] BITTU
[B.S.] BITTU - avatar
0
Yes, it return a boolean true or false
19th Nov 2019, 9:55 AM
ODLNT
ODLNT - avatar