This question already has answers here:
Is Chrome’s JavaScript console lazy about evaluating objects?
(7 answers)
console.log(array) returns filled array, but console.log(array.length) is 0? [duplicate]
(1 answer)
Closed 3 years ago.
Can someone please explain to me, because I don't understand something here, why the same array has two lengths? I assume I understand something wrong here, it must have the same length, right?
I have this call:
console.log(eventsBeforeRender);
console.log(eventsBeforeRender.length);
and in browser console i see this:
What I want to achieve, is to access the element [0] of the root array, so then from this element I can access other elements, of which from what I see there should be 17.
Calling this:
console.log(eventsBeforeRender[0]);
returns undefined.
Related
This question already has answers here:
console.log() shows the changed value of a variable before the value actually changes
(7 answers)
Is Chrome’s JavaScript console lazy about evaluating objects?
(7 answers)
console.log() async or sync?
(3 answers)
Weird behavior with objects & console.log [duplicate]
(2 answers)
Closed 7 months ago.
Hey mods the other question you linked had nothing to do with mine. Even on that questions page it says that the behavior doesn't exist anymore.
To preface, this isn't an issue with the variable i in the closures all being the same although it might look like it is.
The following code has a weird behavior. Basically the code runs the body of a for loop 3 times where it creates a set timeout that modifies and logs the same array.
const obj = {a:1,b:{c:2}};
console.log(obj);
obj.b.c = 3;
I expected when expanded the log would show that c was 2, but it actually shows that c is 3.
Why does this happen?
(I already answered below)
What is happening is that when you console.log a object only the first level of properties are stored before expanding in the console(clicking the > on an object property and seeing its properties). Think about the alternative, you deep copy every object that is logged. Then because of properties like __proto__ and constructor you would have to copy many many items. And if the object happens to have some reference to window you would practically have to take a memory snapshot.
This question already has answers here:
console.log() async or sync?
(3 answers)
Is Chrome’s JavaScript console lazy about evaluating objects?
(7 answers)
Closed 1 year ago.
I have the strange behavior (as i think) of console.log. So, there is two console.log in my console, first shows PdfViewerApplication object, second shows it's fieid, named eventBus.
So, as you can see second line says that PdfViewerApplication.eventBus right?
Now lets look at first line (before! second) , expand the body of the object and find eventBus field.
Obviously it is not null there, it almost has 2 eventListeners (pagesloaded)!
How is it possible?
This question already has answers here:
console.log() async or sync?
(3 answers)
console.log() shows the changed value of a variable before the value actually changes
(7 answers)
Closed 3 years ago.
I have the following javascript line:
console.log({fieldMeta__value: fieldMeta.value, fieldMeta: fieldMeta});
As you can see, I am printing to console the object fieldMeta and, also, its field value. The problem is that its field value (fieldMeta.value) returns 1, but the whole objects prints the content for value as undefined:
I am pretty sure I have some flaw in my logic, but I can't find it.
EDIT
I tried another approach for printing the values:
console.log(fieldMeta);
console.log(fieldMeta.value);
And I got the same result:
This question already has answers here:
Checking if an array has some items in coffeescript
(3 answers)
Closed 8 years ago.
I am trying to figure out if an array is empty. I tried this and it does not work.
a = []
if a == []
alert "empty"
I know I can check the length of the array but am curious why this does not work.
There is no direct empty check for arrays. You could do something like this though:
a = []
alert("empty") unless a.length
This question already has answers here:
Testing for an empty array object in JSON with jQuery
(5 answers)
Closed 8 years ago.
I have the following JSON object that is passed to one of my functions …
{"action":"setProjectAll", "application":{"proId":"new","zoomPosition":35,"scrollerPosition":0,"language":"en","timelinePosition":0}, "clips":[]}
How can I test this object for the propertie "clip" to be "[]" (empty)?
Right now in the example above it is empty, however since the object is dynamic I need to test for that property if it contains values or not.
How can that be done?
thank you
How about
if (x.clips && x.clips.length === 0)