nico-c
2/20/2017 - 11:38 PM

Objects and function in arrays

Objects and function in arrays

var arr = [
  1, // you can have a number
  false, // a boolean
  {name: 'Piper'}, // an object
  function(name){  // a function
    var greeting = 'Hello ';
    console.log(greeting + name);
  },
  'i <3 Dillon' // or a string in an array
]

console.log(arr[2].name) // => Piper -- log the object value
arr[3](arr[2].name); // => Hello Piper  -- calls the function using the object