I want to check if an array contains only objects. So I created this function:
function arrayContainsObjOnly(arr){
return arr.join("").replace(/\[object Object\]/g, "") === "";
}
Here is how you would use it:
// return true
arrayContainsObjOnly([
{"name" : "juan", "age" : 28},
{"name" : "pedro", "age" : 25}
]);
// return false
arrayContainsObjOnly([
{"name" : "juan", "age" : 28},
"name=pedro;age=25"
]);
Is there any cleaner way to do this? Is using the literal "[object Object]"
for checking is safe?
I also prefer a non-jQuery solution.