I'm looking for an way to return an array of only a single property of an array of objects in Javascript. Specifically, if I have an array structure formatted to the following specification:
[
{ prop1: "someVar", prop2: "anotherVar" },
{ prop1: "foo", prop2: "bar" },
{ prop1: "abc", prop2: "def" }
]
How can I return an array of just the prop1 properties? Like following:
[ "someVar", "foo", "abc" ]
I thought I could simply use the .filter method on my original array, like so:
self.myArray.filter(function (el) {
return el.prop1;
});
But that clearly doesn't work... Ideas?