Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to slice every element of array in React

I have an array of elements: [AdsAyush, AdsFace, AdsKicks, AdsMac]
I want to slice every element of this array (remove Ads) and get the result as [Ayush, Face, Kicks, Mac].

How can I slice the "Ads" from every element of this array.

I am doing something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

array.forEach(element =>
  return element.toString().slice(3);

But this is giving me error and not sure what to do?

>Solution :

You can use the function Array.prototype.map as follows.

const array = ["AdsAyush", "AdsFace", "AdsKicks", "AdsMac"];
const result = array.map(element => element.slice(3));

console.log(result);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading