0
[{foo : 'blar', baz: 'hey'}, {x : 'fum', baz: 'another hey'},{x : 'ack', baz: 'yet another hey'} ]
.map(obj => {
    for (var prop in obj){ 
     if (prop !== 'baz'){ 
        return {prop : obj[prop]};
     }
    }
})

I'd like to get an array which contains these objects sans thebaz property in each.

I am getting this right now....

[
 {prop: "blar"},
 {prop: "fum"},
 {prop: "ack"}
]

Should be:

[
 {foo: "blar"},
 {x: "fum"},
 {x: "ack"}
]
Antonio Pavicevac-Ortiz
  • 4,898
  • 8
  • 40
  • 94
  • Your `return` inside the `for` loop cancels the loop immediately which is ok for now since your objects only have 2 properties but would exclude others if there were more. I think it should be obvious why your keys are all `prop` – Phil Dec 06 '17 at 22:41
  • 1
    Why not just delete `baz`? `[{foo : 'blar', baz: 'hey'}, {x : 'fum', baz: 'another hey'},{x : 'ack', baz: 'yet another hey'}].map(item=>(delete item.baz, item));` – Joseph Marikle Dec 06 '17 at 22:44
  • `var a = [{foo : 'blar', baz: 'hey'}, {x : 'fum', baz: 'another hey'},{x : 'ack', baz: 'yet another hey'} ] .map(obj => { for (var prop in obj){ if (prop !== 'baz'){ var ab = {}; ab[prop] = obj[prop] return ab; } } }); ` You can try this. – JSingh Dec 06 '17 at 22:56

0 Answers0