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:
xxxxxxxxxx
1
const resultArray = myArray.filter(element => element === 'string value here ...');
In this example, we use Array.prototype.filter()
to search for 'C'
element in the given array and save the result inside resultArray
.
xxxxxxxxxx
1
const myArray = ['A', 'C', 'D', 'C'];
2
const resultArray = myArray.filter(element => element === 'C');
3
4
console.log(resultArray); // [ 'C', 'C' ]