0

In javascript, how can I do, with elegant code, that:

[div#id1, div#id2, ...]

replace the array’s elements with their respective innerHTML like so

[div#id1.innerHTML, div#id2.innerHTML, ...]

without using loops but with something built into js like for example the .filter() fuction for being clean and concise.

The arrays can also be HTMLCollections; it’s no problem.

And I surely prefer a solution that covers all the field variables of the elements, and not only their innerHTML.

1
  • thanks for the edit. still new to it Commented May 19, 2020 at 22:38

1 Answer 1

1

Use map()

newArray = array.map(div => div.innerHTML)
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.