var array2 = [3,6,7,8,1];
array2.slice(1);

will produce [6, 7, 8, 1]

Note that slice copies the array's contents only one level deep. What that means technically is that nested arrays or objects within the output of slice are still references to the same arrays or objects contained in the original parent array. What that means to you practically is that changing an element or property in the nested arrays/objects returned from slice will also change the same element or property within the nested array or object contained in the original parent array.

Answer from Joseph Myers on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › check-an-array-of-strings-contains-a-substring-in-javascript
Check If An Array of Strings Contains a Substring in JavaScript - GeeksforGeeks
February 27, 2026 - The code uses Lodash's _.strContains() method from the lodash-contrib library to check if the string "abc" contains the substring "a". The result is stored in the variable bool. Using a for of loop and indexOf iterates through each string in the array.
Discussions

javascript - How do you search an array for a substring match? - Stack Overflow
I need to search an array in JavaScript. The search would be for only part of the string to match as the string would have additional components. I would then need to return the successfully matched More on stackoverflow.com
🌐 stackoverflow.com
September 1, 2018
Is there a javascript method to find substring in an array of strings? - Stack Overflow
Suppose my array is ["abcdefg", "hijklmnop"] and I am looking at if "mnop" is part of this array. How can I do this using a javascript method? I tried this and it does not work: var array= ["abcd... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Substring in array of objects - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
How do I only replace the first instance of a substring?
Solved. In case you also need it, and you're using regexes: string = string.left(regex_match.get_start()) + (string.right(string.length() - regex_match.get_end())) This basically just adds the string that's to the left of the match to the string that's to the right of it, skipping over it. More on reddit.com
🌐 r/godot
2
1
March 31, 2024
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript - MDN Web Docs
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.
Top answer
1 of 14
105

People here are making this waaay too difficult. Just do the following...

myArray.findIndex(element => element.includes("substring"))

findIndex() is an ES6 higher order method that iterates through the elements of an array and returns the index of the first element that matches some criteria (provided as a function). In this case I used ES6 syntax to declare the higher order function. element is the parameter of the function (which could be any name) and the fat arrow declares what follows as an anonymous function (which does not need to be wrapped in curly braces unless it takes up more than one line).

Within findIndex() I used the very simple includes() method to check if the current element includes the substring that you want.

2 of 14
94

If you're able to use Underscore.js in your project, the _.filter() array function makes this a snap:

// find all strings in array containing 'thi'
var matches = _.filter(
    [ 'item 1', 'thing', 'id-3-text', 'class' ],
    function( s ) { return s.indexOf( 'thi' ) !== -1; }
);

The iterator function can do whatever you want as long as it returns true for matches. Works great.

Update 2017-12-03:
This is a pretty outdated answer now. Maybe not the most performant option in a large batch, but it can be written a lot more tersely and use native ES6 Array/String methods like .filter() and .includes() now:

// find all strings in array containing 'thi'
const items = ['item 1', 'thing', 'id-3-text', 'class'];
const matches = items.filter(s => s.includes('thi'));

Note: There's no <= IE11 support for String.prototype.includes() (Edge works, mind you), but you're fine with a polyfill, or just fall back to indexOf().

🌐
ReqBin
reqbin.com › code › javascript › i5foejaa › javascript-substring-example
How do I get a substring from a string in JavaScript?
2 weeks ago - To get a substring from a string in JavaScript, you can use the built-in string.substring(start, end) method. The first parameter specifies the index of the first character from which to get the substring (in JavaScript, indexing starts from zero).
🌐
Squash
squash.io › javascript-substring-splice-and-slice-the-complete-guide
How to Use Javascript Substring, Splice, and Slice
May 1, 2023 - Related Article: How to Remove a Specific Item from an Array in JavaScript · Javascript substring is a method used to extract a portion of a string. It takes two arguments: the starting index and the ending index.
Find elsewhere
🌐
Refine
refine.dev › home › blog › tutorials › javascript substring method
JavaScript Substring Method | Refine
January 1, 2025 - In the end, we point out how JavaScript ... String.prototype.substr(). ... Array.prototype.substring() takes two possible arguments: a startIndex and an endIndex....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › split
String.prototype.split() - JavaScript - MDN Web Docs
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how to split a string into substrings in javascript
How to Split a String into Substrings in JavaScript — SitePoint
November 6, 2024 - The split() method divides a string into an array of substrings based on a specified separator and returns the new array. On the other hand, the substring() method extracts characters from a string between two specified indices and returns the ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-string-substring-method
JavaScript String substring() Method | GeeksforGeeks
November 28, 2024 - JavaScript String.at() method is used to find the character at the specified index. This method is capable of taking both positive and negative indexes. The positive index finds the element from the start of the array and the negative index ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript - MDN Web Docs
String.prototype.substring() Array.prototype.slice() Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Jul 10, 2025 by MDN contributors.
🌐
Edureka
edureka.co › blog › javascript-substring
JavaScript Substring() | How is it different from substr() & slice()? | Edureka
January 9, 2025 - This Edureka blog is about the JavaScript substring() whih is an inbuilt function that returns a part of the given string from start index to end index.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-string-substr
JavaScript String substr() Method - GeeksforGeeks
May 15, 2023 - Example 4: In this example, the method substr() extracts the substring starting at index 7 from the end of the array, and the length of the string is 6. Output: In this example, the method substr() creates a substring starting from index 7 from the end of the string till the end of the string. ... We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-substring-examples-slice-substr-and-substring-methods-in-js
JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS
March 22, 2020 - Note: We can use the slice( ) method also for JavaScript arrays. You can find here my other article about the slice method to see the usage for arrays. According to the Mozilla documents, the substr( ) method is considered a legacy function and its use should be avoided.
🌐
Bennadel
bennadel.com › blog › 2159-using-slice-substring-and-substr-in-javascript.htm
Using Slice(), Substring(), And Substr() In Javascript
April 21, 2020 - And, in his examples, Haverbeke makes frequent use of the String method, slice(). When I think of slice(), I think of extracting portions of a Javascript array; I don't think I was even aware that the Javascript String prototype had a slice() method. To clear up my own confusion and misconceptions, I wanted to take a quick look at the various ways in which Javascript allows for partial string extraction. From what I can see, there are three primary methods for substring extraction:
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript string methods › string.prototype.substring()
JavaScript Substring(): Extract a Substring from a String
November 3, 2024 - Then the substring returns the domain that starts from the index of @ plus 1 to the end of the string. The JavaScript substring() method returns the substring from the start index up to and excluding the end index.