I want to pass 10 different objects into a function (logObjekt) so that I can console.log the property name which is setup inside all objects.
Instead of having to write 10 lines of code to make this possible I am using a for loop to increment each name that's going to be passed to the function, I made this possible because all objects starts with "objekt".
When I debug this everything looks good and I get the result "object1, object2 ... and so on" when JS coerce the int to string and combine the two. So at first glance I thought iI got a good solution but when I implemented the solution I got 10x undefined instead of 10 values from the objects.
var objekt1 = { "name": "value1" };
var objekt2 = { "name": "value2" };
var objekt3 = { "name": "value3" };
var objekt4 = { "name": "value4" };
var objekt5 = { "name": "value5" };
var objekt6 = { "name": "value6" };
var objekt7 = { "name": "value7" };
var objekt8 = { "name": "value8" };
var objekt9 = { "name": "value9" };
var objekt10 = { "name": "value10" };
var i;
for (i = 0; i < 10; i++) {
logObjekt("objekt" + i);
};
function logObjekt(objekt) {
console.log(objekt.name)
};
I expect to log properties in the objects thats called "name".
Right now to actual result is 10x undefined.