0

How do I view and extract data inside a variable, populated from another piece of code, that may contain hidden escape characters or data in Javascript (JQuery stuff is fine too)?

For example lets say I have an Ajax call such as this, where data is printed from a back-end script written in Lua:

success: function(data)
{
    dataItems = data.split(",");
}

Lets say I'm expecting a four letter string in each of the dataItems array. If I use Chrome or Firefox putting a breakpoint on dataItems I see each array containing a four letter string and I'm happy because it looks right and I can now process it. However if I do a print(dataItems[1].length) for example I notice it has a length of 5, and my debugger shows dataItems[1]="abcd", obviously there is something hidden inside it that doesn't show easily as part of the arrays variable. Is there a better way to catch and view these hidden pieces of information preferably in a browser debugger? How does one go about removing this undesired data once it is recognized.

0

1 Answer 1

1

I think it's surrounded with empty spaces. Try:

console.log(dataItems[1].trim().length);
Sign up to request clarification or add additional context in comments.

2 Comments

This does work! Is there a better way to identify this in the common browsers debuggers?
It's an empty space, you won't see that. What I normally do is try highlighting(selecting) the text in the console. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.