I have this simple array:
var a = new Array();
a.push(o);
When running this code:
a.forEach(function(o){console.log(o)});
In a blank page - I can see the object being logged to the console.
The thing is - I have this code running in a another page and
The foreach loop does not log anything, even though I can see the object in a[0].
I suspect this may has to do with the Prototype JS lib that this page utilizes- though I wasn't able to prove it.
Does that sound familiar?
Thanks.
The prototype replaces console log messages, use this code to see the actual console log:
delete console.log
After this console messages will appear.
Related
This is really puzzling me, until 4 days ago everything was working fine and no problems were occurring, but then an issue started when two of my cron daemon jobs stopped working.
I thought nothing of it and decided to rebuild the code and improve it a little as I have gained more insight since the files were coded the first time around.
Here is the problem:
this one works as expected on local machine
Object.keys(res).forEach(function(key) {
const row = res[key];
client.channels.get(row.forchannel).send({ embed });
console.log(row.forchannel);
});
and so does this one:
res.forEach(function(row) {
client.channels.get(row.forchannel).send({ embed });
console.log(row.forchannel);
});
and also this one:
for (let i = 0; i < res.length; i++) {
console.log(res[i]);
client.channels.get(res[i].forchannel).send({ embed });
}
The issue I have is that non of them work when I upload to live server, the results from a MySQL query are there when I console log out of the loop on live, console logging inside the loop on live shows nothing except for the last block of code I posted and this returns one result.
Local machine is windows running Node v11.6 and live is Ubuntu running a v11.12 of node.
So to summary:
On the live server those loops above are not working, I can return arrays when console logging data outside of the loops but on only the last one does any data show when console logging inside the loop.
On local machine everything works as expected, In both cases error catching reports null so there are no errors.
res.map((result) => {
client.channels.get(result.forchannel).send({ embed });
});
It might help you.
I discovered what the problem was, although my bot has both a subscribe and an unsubscribe option my code does not cater for the obvious: A discord server Admin deleting a channel, this then leaves a row in the database that when fed into the loop comes back false as the channel no longer exists and stops the auto-posting.
Working code first checks if the channel does actually exist before processing through the array.
res.map((result) => {
if (client.channels.has(result.forchannel)) {
client.channels.get(result.forchannel).send({ embed });
}
});
client.channels.has checks that the channel exists and because its in an if statement will only proceed to post on channels that return true.
I'm using ParseJS to try and get the data from a user (from another object) and no matter what I try it doesn't seem to be working, i thought it would be as simple as doing:
var message = results[i].get('Messager').get('username');
To keep in mind:
var message = results[i].get('Messager'); // gives me message object perfectly fine
var message = results[i].get('Messager').id; // gives me user id perfectly fine
Since without .get('username') it works fine i'm unsure why it's not working. I've used the console to inspect that object and the data i want is stored normally inside the object, even when i do:
console.log(results[i].get('Messager'));
and then save as a temp variable inside the Chrome console then use:
temp1.get('username');
It works fine, this is really bothering me because i dislike the workaround.
What am i doing wrong? Why is doing .get('Messager').get('username'); not working?
There are no spelling/capital mistakes in what I'm doing
Here is an image with the .message object when i do console.log(results[i].get('Messager');
After further testing I found that the 'Messaging' object works but 'Messager' object doesn't work? The objects look the exact same..
I am having a very weird problem. Using $http my response is not getting marshalled correctly into map/object. The data is a map of lists. The issue is that the element 100110150000000751 has a value from the raw data in the first log "1 group data[". but after its converted to json it has the value of an empty array. You can see the image of the "after conversion" log. This all works fine in chrome with debugger open but not if debugger is closed. The method is so simple and there is little to no room for race conditions or anything. I created a little desktop html file with all the same libraries and just calling a function without $http and it works without issue. Angular 1.4.5 Any help is much appreciated.
transformResponse: function(groupMapResponse){
console.log("1 group data ["+groupMapResponse+"]");
var asdfdsafsad = (typeof groupMapResponse === 'string')?JSON.parse(groupMapResponse):groupMapResponse;
console.log("after conversion:",asdfdsafsad);
return asdfdsafsad;
}
The console log is:
1 group data [{"1000110150000002801":["1000110020000007753"],"1000110150000002855":["1000110020000009470"],"1000110150000004452":["1000110020000007895"],"1000110150000004362":["1000110020000006355"],"1000110150000004361":["1000110020000010309"],"1000110150000000751":["1000110020000007950"],"1000110150000004412":["1000110020000006353"]}]
Turns out the issue was not in marshalling at all. The object was already linked to a bound object and was later altered but the log message was updated with the bound value. Anyway...
This GitHub issue documents that the console doesn't output anything to the meteor shell. Are there any workarounds? By default all console.log() statements will be output in the app's STDOUT (not in the shell).
Let's say we want to print certain items from a collection:
Meteor.users.find().forEach(function (user) {
if (...) console.log(user.emails[0].address;
});
That won't print anything. Here's what I've tried:
process.stdout.write() - doesn't print anything
Create a string buffer, append what we want to log to it, and evaluate it.
var output = '';
Meteor.users.find().forEach(function (user) {
if (...)
output += user.emails[0].address + "\n"
});
output;
This works but the \n is echoed literally, not as a line feed.
Evaluate the expression in the function. Predictably, this doesn't print anything.
One workaround I've used is to run the app in the background, then run the shell in the same window. i.e.
meteor run &
meteor shell
That way, everything that gets output in the app's console gets printed to your window. Admittedly, this won't help if you want to log only specific messages to your shell, but it helps if all you want is to avoid switching back and forth between multiple windows all the time.
I'm attaching response data to the target of a jquery plugin when a preload option is set. It all seems to work a charm except the data I set is inaccessible. When I log $(elm).data(); I can see that the object was returned with the appropriate data set to the appropriate key. But when I try console.log($(elm).data('key')); I get undefined. I also get undefined when I try var elmData = $(elm).data(); console.dir(elmData.key);. So I'm logging the object on one line, seeing it in the console, trying to access a property I just confirmed exists and getting undefined.
Here is my function:
this.preloadData = function(folders)
{
var getString;
for(var folder in folders ){
getString = 'folder='+folders[folder]+'&uri='+uri+'&thumbSide='+options.thumbSide;
$.get(options.handler, getString,
function(response, serverStat, xhr)
{
$self.data(folder, response);
});
}//for
var $selfData = $self.data();
console.log($selfData);//Object{ editorial : "data", testingdata : 'some meaningless words'}
console.log($self.data());//Object{ editorial : "data", testingdata : 'some meaningless words'}
console.log($self.data.editorial);//undefined
console.dir($self.data('editorial'));//undefined
console.log($selfData['editorial']);//undefined
console.log($selfData.editorial);//undefined
$self.data('testingdata', 'some meaningless words');
console.log($self.data());//Object{ editorial : "data", testingdata : 'some meaningless words'}
console.log($self.data('testingdata'));//'some meaningless words'
}
I know the namespacing is too simple, I just tried to cut out as many factors as I could to try and understand why this isn't working. I'm developing in chrome but I've tried it in firefox also and get the same.
-----------------------------EDIT------------------------------------------
I understand what the problem is now. The console reflects all changes to an object that get made regardless of if they were made when the object was logged. So when I logged the object the property didn't exist yet because the response had yet to come back from the server, but the log still shows the property as existing because at some later point in the script execution it DID exist. Because primitive values aren't logged in the same way, the call to log the property shows up as undefined because it WAS undefined. If I refer to the property some seconds later, say on a click event it is defined(which is how I intended it to work anyway). I just got really caught up in debugging this function before I actually implemented it.
Can you do this?
$self.data['editorial']
try
console.log($self.data.editorial);