I have an array of objects with the following structure:
let arr = [
{name: "abc", show: true , display:"ABC"},
{name: "xyz", show: false , display:"XYZ"},
{name: "pqr", show: true , display:"PQR"},
{name: "lmn", show: false , display:"LMN"}
]
I want the output to be two arrays, one for show:true and the other for show:false, i.e., based on the value of show property. Ideally, a single function that gives me both the arrays would be great. I'm expecting next output:
arr1 = ["abc", "pqr"]
arr2 = ["xyz", "lmn"]
My current approach is:
// Approach I have tried so far:
var results = arr.filter(function(entry) {
return entry.show === false;
});
But this gives me an array of objects, and instead I want an array with names. Can someone help me with this?