0

I have some code:

console.log("444444: ", profile, JSON.stringify(profile))

when I check the log:

log

Basically I want to know why I can not see

value: [0]

and i want to pass this profile object to backend and looks like backend is not getting this value field.

4
  • 1
    Please don't post screenshots of code, but it looks like value is an array containing the number 0? Commented Mar 2, 2022 at 23:07
  • @wooooooo yes, value is an array containing 0, i wonder why it does not show up when I log the object, however when I do JSON.stringfy, I am able to find this value. Also, when I pass this object to next function, looks like it does not contain this value [0] Commented Mar 2, 2022 at 23:12
  • 1
    In the console log in your screenshot, it does show up. Array(1) means it is an array with a length of 1, which is the [0] you see stringified. Make sure you log it immediately before passing it to the next function, and then check how that function accesses the object. Commented Mar 2, 2022 at 23:23
  • The data is not different, but browsers just show less output when you console.log to reduce clutter. Specifically they only nest a few levels deep before they start summarizing. The JSON.stringify() version is what really gets sent if you json-encode it, so if you're missing something in the backend the issue has nothing to do with how console.log() shows things. Commented Mar 2, 2022 at 23:48

2 Answers 2

1

Probably, you remove profile.value somewhere after you outputted it to console.log(). Try looking for delete profile.value; or profile.value = undefined;.

Sign up to request clarification or add additional context in comments.

4 Comments

as you can see in my code, i console log profile and JSON.string(profile) at the same time. from the result, I can see value: [0] in json output, but not the profile object output. I did not delete it anywhere, at least from this line of console.log
@ilikechocolate This answer is correct, the object is logged to the console with the property, but by the time you click the drop down it is gone. I am able to reproduce this behaviour by adding delete profile.value after the console.log.
@ilikechocolate This stems from the fact that your browser lazy loads the properties. You can see the difference between lazy loading and pre-loading here: stackblitz.com/edit/angular-ivy-pymdqv?file=src/app/…. Stackblitz loads the properties at the time of logging, while firefox loads them when you click the dropdown.
@ChrisHamilton thanks for your information.Weird part is, if I change the value from [0] to [1], then I am able to see the value [1].
1

Try to parse the data first and then stringify

JSON.parse(JSON.stringify(profile)) 

Comments

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.