i have a question here: why cant i use "." instead of "[]",to call a property of the object??
function filter(array, prop) {
var result = array.map(x=>{
return x[prop]
})
return result
}
filter([{ name: 'TV LCD', price: 100}, { name: 'PC', price: 500 }],"name")
//[ 'TV LCD', 'PC' ]
function filter(array, prop) {
var result = array.map(x=>{
if(x.name===prop){
return x
}
})
return result
}
filter([{ name: 'TV LCD', price: 100}, { name: 'PC', price: 500 }],"name")
//[undefined,undefined]
sorry for my english :/
i want the "name" property of the object, but in the console shows: [undefined,undefined]