I want to create new array based on keyword.
if my search key word is
- "align-center" result should be ["align-center"]
- "align" result should be ["align-left", "align-center", "align-right"]
- "right" result should be ["align-right"]
- "arrow" result should be ["align-left", "align-right"]
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 *****
});
First use
map()to get the key of each object in the array. Then usefilter()to return the ones that match the search string.