JavaScript gets the JSON object's key name in two ways of data processing, you may receive a JSON object in an indeterminate content format, and then extract the value of the key. Today, we tried two methods to extract the JSON key, all of which worked correctly. Let's look at the first method.
jsonobj = {Name: ' Richard ', Value: ' 8 '}
for (key in jsonobj) {
Console.log (key);
Add your statement to get key value
}
result
Name
Value
The second method of
In JavaScript, object has a key property that can return an array of key of the JSON object
(Object has a property keys, returns an Array of keys from that Object)
Usage:
object.keys (jsonobj)
jsonobj = {Name: ' Richard ', Value: ' 8 '}
Console.log (Object.keys (jsonobj));
result
[ ‘Name‘, ‘Value‘ ]
The second method is relatively convenient to obtain the results.
Two ways JavaScript gets the key name of a JSON object