0

Why can't I make a function that logs my data?

If I don't do console.log in the function, I'm getting the values, but when doing it in a function, the data is hidden.

let stoneArray = [];
let beginningStone = {
  a: 200,
  b: 200,
  c: 10,
  d: 2,
  e: 5
};
stoneArray[0] = beginningStone;

function consoleData() {
  console.log('stoneArray = ' + stoneArray);
}
consoleData();
console.log(stoneArray);
Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
AnonymousUser
  • 690
  • 7
  • 26
  • `console.log('stoneArray = ' + stoneArray);` In the statement, you are appending to string, and so the object is appended as `[object object]`. Try logging without string. e.g - `console.log(stoneArray);` – Anita Mar 01 '21 at 06:59
  • aha, that's why. Thanks. – AnonymousUser Mar 01 '21 at 07:03
  • You can use a comma to separate the object from the string like `console.log('stoneArray = ', stoneArray);` – Bandhan Mar 01 '21 at 07:08

1 Answers1

1
function consoledata() {
   console.log(stoneArray)
           }

**Try This code **

Rajasekhar
  • 121
  • 1
  • 4