Languages
[Edit]
EN

JavaScript - extract string item from array

3 points
Created by:
Kenya-Spears
860

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' ]

References

  1. Array.prototype.filter() - JavaScript | MDN
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join