zok
zok

Reputation: 7882

Weird console.log behavior in Chrome dev tools?

In Chrome Dev Tools, you console.log an Array. It shows: (4)[Location, Location, Location, Location]: perfect, that's what I expected.

You click on it, to reveal the elements, and it shows:

screenshot

How is this possible?

Upvotes: 1

Views: 493

Answers (2)

Red
Red

Reputation: 7299

The console will log the array. You see three properties inside it. When you delete a property later on, and you open the console. You will only see the remaining properties.

See this snippet, and check the console in your browser.

var array = [{name: 'helle'}, {name: 'Google'}, {name: 'Bonjour'}];

console.log(array);

delete array[2];
    

Just a visualization of the anwser given by @Felix Gaebler

Upvotes: 1

Felix Gaebler
Felix Gaebler

Reputation: 743

This happens when the element is edited after it was logged. Chrome just shows you a pointer to that element. If 2 and 3 are removed after console.log() they are shown in the preview, but not when you inspect the element.

Upvotes: 5

Related Questions