From 2b4d7c6ee52adb792881f757043ef5102cb1981c Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Fri, 15 Dec 2017 16:30:12 +0530 Subject: [PATCH] Added snippet for array includes --- snippets/array-includes.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 snippets/array-includes.md diff --git a/snippets/array-includes.md b/snippets/array-includes.md new file mode 100644 index 000000000..c068d17b2 --- /dev/null +++ b/snippets/array-includes.md @@ -0,0 +1,10 @@ +### Array includes + +Use `slice()` to offset the array/string. `Array.indexOf()` returns `-1` if the sub-string/array dosen't contain the given `value`. + +```js +const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1; + +// includes("30-seconds-of-code", "code") -> true +// includes([1, 2, 3, 4], [1, 2], 1) -> false +``` \ No newline at end of file