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);
3
  • 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); Commented Mar 1, 2021 at 6:59
  • aha, that's why. Thanks. Commented Mar 1, 2021 at 7:03
  • You can use a comma to separate the object from the string like console.log('stoneArray = ', stoneArray); Commented Mar 1, 2021 at 7:08

1 Answer 1

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

**Try This code **

Sign up to request clarification or add additional context in comments.

1 Comment

console.log("stoneArray = ", stoneArray); works as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.