I have a javascript code within an html file. My goal is to display the list properties and methods of a given object. This is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Display properties and methods from objects</title>
</head>
<body>
<script type="text/javascript">
var tuna = 'tuna'
var listPropertiesMethods = Object.getOwnPropertyNames(tuna)
for (i=0; i<listPropertiesMethods.length; i++){
console.log(listPropertiesMethods[i])
}
</script>
</body>
</html>
As u can see I am using the method Object.getOwnPropertyNames
to get the list of properties of my object (variable) tuna
.
The output that I get to the console is this:
0
1
2
3
length
I understand the method length because if I type tuna.length
I get the number of characters of the variable. However if I type tuna.0
or tuna.1
I get error! What are those 0, 1, 2, 3
properties/methods? how can I use them?
PS: I am beginner...