我的对象中有这些数组,我需要filter
tags
具有特定值的数组。我不知道如何实现这一目标
const obj = [
{
"slug": "add-an-aggregate-rating-feature-to-your-website",
"frontmatter": {
"title": "Add An Aggregate Rating Feature To Your Website",
"metaTitle": "Add An Aggregate Rating Feature To Your Website",
"tags": [
"structured-data",
"aggregate-rating",
"rich-text"
]
}
},
{
"slug": "step-by-step-guide-to-become-a-full-stack-web-developer-in-2023",
"frontmatter": {
"title": "Step-by-Step Guide: How to Become a Full Stack Web Developer in 2023",
"metaTitle": "Step-by-Step Guide: How to Become a Full Stack Web Developer"
"tags": [
"article",
"roadmap"
]
}
},
{
"slug": "what-is-dall-e",
"frontmatter": {
"title": "What is DALL-E? A world changing technology?",
"metaTitle": "What is DALL-E? A world changing technology?"
"tags": [
"technology",
"article",
"openai"
]
}
}
]
// List objects having article tag only
var newArray = obj.filter(function (el){
return el.frontmatter.tags.filter(function (el2){
el2 == "article"
})
})
console.log(newArray)
我很确定您想要过滤obj
array
const newArray = obj.filter((el) =>
el.frontmatter.tags.includes("article")
)
const obj = [{
"slug": "add-an-aggregate-rating-feature-to-your-website",
"frontmatter": {
"title": "Add An Aggregate Rating Feature To Your Website",
"metaTitle": "Add An Aggregate Rating Feature To Your Website",
"tags": [
"structured-data",
"aggregate-rating",
"rich-text"
]
}
},
{
"slug": "step-by-step-guide-to-become-a-full-stack-web-developer-in-2023",
"frontmatter": {
"title": "Step-by-Step Guide: How to Become a Full Stack Web Developer in 2023",
"metaTitle": "Step-by-Step Guide: How to Become a Full Stack Web Developer",
"tags": [
"article",
"roadmap"
]
}
},
{
"slug": "what-is-dall-e",
"frontmatter": {
"title": "What is DALL-E? A world changing technology?",
"metaTitle": "What is DALL-E? A world changing technology?",
"tags": [
"technology",
"article",
"openai"
]
}
}
]
const newArray = obj.filter((el) =>
el.frontmatter.tags.includes("article")
)
console.log(newArray)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)