+ 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
CoderBittu
CoderBittu - avatar
6 odpowiedzi
+ 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
CoderBittu
CoderBittu - 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
CoderBittu
CoderBittu - avatar
0
Yes, it return a boolean true or false
19th Nov 2019, 9:55 AM
ODLNT
ODLNT - avatar