Here is my code:
var myObject = [];
function something() {
myObject.push("thing");
}
function other() {
console.log(myObject);
}
How can I let other see the items pushed into myObject by something?
It's declared globally - so just calling something() then other() will ensure that there are elements in the array. If you were calling them in the wrong order, then the function was displaying the empty array first, then adding an element to it.
var myObject = [];
function something() {
myObject.push("thing");
}
function other() {
console.log(myObject);
}
something();
other();
If you want to log each item on a separate line:
var myObject = [];
function something() {
myObject.push("thing");
}
function other() {
myObject.forEach(e => console.log(e));
}
something();
something();
something();
other();
Also, you're dealing with an array, not an object. An object looks like this:
var anObject = {
key1: "value1",
key2: true,
key3: 42.01
};
console.log(anObject);
console.log(myObject[0])?otherbeforesomething...