You can use map
on your array.
So based on my previous answer, this is how you can achieve that.
const myArray = [
{
author: 1,
content: {
rendered:
'<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>
<p><a href="file.pdf"></a></p>
<p><img src="image.jpg"/></p>',
protected: false
}
},
{
author: 1,
content: {
rendered:
'<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>
<p><a href="file.pdf"></a></p>
<p><img src="image.jpg"/></p>',
protected: false
}
},
{
author: 1,
content: {
rendered:
'<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>
<p><a href="file.pdf"></a></p>
<p><img src="image.jpg"/></p>',
protected: false
}
}
]
const extractData = obj => {
let content = document.createElement('div')
content.innerHTML = obj.content.rendered
let description = content.querySelector('p').innerText
let image = content.querySelector('img').src
let file = content.querySelector('a').href
return {
description,
image,
file
}
}
const results = myArray.map(extractData)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…