I have trouble to map through a nested object with string and objects, trying to get a list of the "qty" value in array so I can filter out.
data looks like this:
const data = {
'123': {
'name': 'Part 1',
'size': '20',
'qty' : '50'
},
'5678' : {
'name': 'Part 2',
'size': '15',
'qty' : '60'
},
'9810' : {
'name': 'Part 2',
'size': '15',
'qty' : '120'
},
}
// my code I tried:
const getValue = Object.key(data).map(i=> [i].qty) //undefined
// expect return ['50','60','120']
const items = ['4','120','5']
// Expecting remove '120' from this list, because the getValue should have '120' in the array.
const filterItem = items.filter(i => i !== getValue)
Thanks for the help!
Object.keys(data).map(i => data[i].qty). Your current code is creating a new array literal and trying to retrieve theqtyproperty of the array, which doesn't exist.