Skip to content Skip to sidebar Skip to footer

Finding Sub Properties Of Javascript Object

My code ise this: var cem = { 'name': 'cem topkaya' }; f_PropertyBul(cem); function f_PropertyBul(obj) { for (var prop in obj) { document.writeln(obj + ' prop: ' + pr

Solution 1:

Strings are enumerable. For example:

var str = "string"for (var c in str) {
   console.log(str[c]);
}

Returns:

s
t
r
i
n
g

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/propertyIsEnumerable

This method can determine whether the specified property in an object can be enumerated by a for...in loop

If you want to exclude strings, add a check for typeof prop !== "string" in the if statement.

Post a Comment for "Finding Sub Properties Of Javascript Object"