2

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:

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

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

1 Answer 1

2

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);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.