Emiliano Maccaferri Emiliano Maccaferri - 1 month ago 6x
Javascript Question

Check if object doesn't contain a value not working (JS)

I'm having an hard time solving this problem.

For some reason .hasOwnProperty() is not working.

What I want to do is to create a new object (inside another array) when a value (inside an array) doesn't exist in the array I'm currently looping.

I don't know why, but the first condition gets looped everytime, instead of being looped only when the condition is satisfied.

P.S I'm looping into JSON. Example of JSON I'm parsing

var keys = [



var resArray = stats.playerstats.stats;
var statsArray = [];

for (var i = 0; i < keys.length; i++) {
for (var j = 0; j < resArray.length; j++) {
if (!resArray[j]["name"].hasOwnProperty(keys[i])) {
resArray[j]["name"] = keys[i];
resArray[j]["value"] = "None";
"name": resArray[j]["name"],
"value": resArray[j]["value"]
if (resArray[j]["name"] === (keys[i])) {
"name": resArray[j]["name"],
"value": resArray[j]["value"]


Feel free to ask for clarifying.


if (!resArray[j]["name"].hasOwnProperty(keys[i])) {

Obviously this statement is wrong. your resArray[j]["name"] is string, not object. In usual you want to check if one object has some enumable property to use hasOwnProperty method.