user736893
user736893

Reputation:

Search *values* of scope variables in Chrome debugger?

If I set a breakpoint in my app and hit it in the chrome devtools, is there any way to search for a specific value? Say I have a huge object and the variable I'm looking for isn't where I expect it. Perhaps there should be some property that is a string of "foobar". I expect it to be in this.attributes.name but it's not there. Is there any way to find it without clicking through every single value in the DOM?

Upvotes: 0

Views: 1362

Answers (1)

Chirag Bhatia - chirag64
Chirag Bhatia - chirag64

Reputation: 4516

When your app hits the breakpoint, you can run a for loop within your object.

For example, if your object is:

var attributes = {a: 1, b: 2, c: 3, d: 4, e: 5};

and you wish to find out which one of them has a value of 3, you can run a for loop in the JavaScript console within Chrome devtools which would be similar to something like:

for (i in attributes) {
  if (attributes[i] === 3) {
    console.log("3 was found at " + i);
  }
}

Upvotes: 1

Related Questions