EN
JavaScript - extract string item from array
3
points
In this article, we would like to show you how to search and extract string items from an array in JavaScript.
Quick solution:
const resultArray = myArray.filter(element => element === 'string value here ...');
Practical example
In this example, we use Array.prototype.filter()
to search for 'C'
element in the given array and save the result inside resultArray
.
// ONLINE-RUNNER:browser;
const myArray = ['A', 'C', 'D', 'C'];
const resultArray = myArray.filter(element => element === 'C');
console.log(resultArray); // [ 'C', 'C' ]