Creating your own objects


#1

Why the out put displays a element called printAll: [Function] for below code.


var myOwnObject = {
    name: "Mr.Obama",
    age: 48,
    position: "X president of USA"
    };
    

var myObj = new Object();
myObj.name = "Mr.Donald Trump";
myObj.age = 54;
myObj.position = "President of USA";


var object1 = {};
object1.name = "Mr.Modi";
object1.age = 60;
object1.position = "Prime minister of India";

var myArray = [myOwnObject, myObj, object1];

object1.printAll = function(){
    console.log(myArray);  
    };
object1.printAll();


**Output:**
[ { name: 'Mr.Obama', age: 48, position: 'X president of USA' },
  { name: 'Mr.Donald Trump', age: 54, position: 'President of USA' },
  { name: 'Mr.Modi',
    age: 60,
    position: 'Prime minister of India',
    printAll: [Function] } ]

#2

well, printAll is a method, and give you print all properties of the objects, this includes the methods belonging to objects


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.