1

Hello I have an object that I'm convertion into JSON like that :

var myJSON = JSON.stringify(myObject);

the console.log(myJSON); gives :

[{"RowID":"6","Name":"joe","Alias":"ss","Email":"[email protected]","Phone":"123456"}]

How can I count the number of keys inside that json? I want to count 5 items as a result :

RowID, Name, Alias, Email, Phone

I tried to count the elements within the object before the JSON stringify with : console.log(Object.keys(myObject).length); but it gives me 1 not 5

How can I do that?

1 Answer 1

4

That's because myObject is an array. You need to access the first item of the array to get your 5-keyed object.

Object.keys(myObject[0]).length
Sign up to request clarification or add additional context in comments.

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.