已关闭。此问题需要details or clarity。目前不接受回答。
**要改进此问题吗?**通过editing this post添加详细信息并阐明问题。
上个月关门了。
Improve this question
我想根据关键字创建一个新数组。
如果我搜索关键字是
- “居中”结果应为[“居中”]
- “align”结果应为[“左对齐”,“右对齐”,“右对齐”]
- “right”结果应该是[“右-右”]
- “arrow”结果应为[“左-左”,“右-右”]
const myarray = [
{
"align-center": [
"align",
"center"
]
},
{
"align-justify": [
"align",
"justified"
]
},
{
"align-left": [
"align",
"left",
"arrow"
]
},
{
"align-right": [
"align",
"right",
"arrow"
]
}
]
let results = myarray.filter(function (name) { return *****
});
字符串
2条答案
按热度按时间h7wcgrx31#
首先使用
map()
获取数组中每个对象的键。然后使用filter()
返回与搜索字符串匹配的对象。个字符
qc6wkl3g2#
你可以创建一个表示相反关系的对象:
字符串