Suppose I have an array of objects and I want to exclude certain keys/values. Instead of using the traditional delete
method to remove one key/value pair, is there a way to specify which pairs I want to keep and remove all others? For example, in this array of objects, I only wish to retain trackName
, kind
, and price
:
var tracks = [{
trackNumber: "01",
trackName: "Track 1",
trackDuration: "5:35",
kind: "song",
currency: "USD",
price: 1.29
}, {
trackNumber: "02",
trackName: "Track 2",
trackDuration: "5:15",
kind: "song",
currency: "USD",
price: 1.29
}, {
trackNumber: "03",
trackName: "Track 3",
trackDuration: "5:07",
kind: "song",
currency: "USD",
price: 1.29
}, {
trackNumber: "04",
trackName: "Track 4",
trackDuration: "0:16",
kind: "song",
currency: "USD",
price: 1.29
}, {
trackNumber: "05",
trackName: "Track 5",
trackDuration: "5:35",
kind: "song",
currency: "USD",
price: 1.29
}];