Here's the situation: I want to process item-objects with a function. The item-objects have a property "name", but that's only a short version of the fullname.
I also got a list-object, which has shortnames of items as properties, and fullnames as values of these properties. Here are the objects, like you would try in a node-console:
var itemobj = {"name":"a","amount":"10","price":"5"};
var listobj = {"a":"adler","b":"blume","c":"chicken"};
Unfortunately, not all item-objects have a property like their own name-properties value in the list-object. For those I want to set the default-fullname "noname". Here is the code I thought should work:
function fullname(io){
if (listobj.hasOwnProperty(io.name)){
var shortn = io.name;
var fulln = listobj.shortn;
io.fullname = fulln;
} else {
io.fullname = "noname"
}
};
But running the following I get the output shown:
fullname(itemobj);
console.log(itemobj);
{ name: 'a', amount: '10', price: '5', fullname: undefined }
I would expect:
{ name: 'a', amount: '10', price: '5', fullname: 'adler' }
What do I do wrong?