so I am trying to add a property to an object if it doesn't already exist in the Object
so my code basically works
Psudo: (if the property doent exist in the object already add it in)
var names= ["james", "kate", "kara", "milly"];
var storage = {};
var testElement = arr.pop();
if(typeof(storage.testElement==='undefined')){
storage.testElement = '1';
}
else{
storage.testElement = storage.testElement + 1;
}
return console.log(storage);
like I said this is sort of working, the output I get from the console log is { testElement: "1"} Where it says 'testElement' i need that to be the same as the item that was "popped" off the end of the array so in this case the last item in the array is "milly" so i need the object to say { milly: 1 } or { milly: "1" } Can anyone tell me how to change it?