我的对象中有这些数组,我需要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)
3条答案
按热度按时间bfrts1fy1#
我非常确定您要过滤
obj
数组w8ntj3qf2#
使用
filter
和includes
创建优雅的一行程序e5nqia273#
希望这对你有帮助。