Default Values for JSON in javascript?

You can use the or operator to assign default values in case the aren't defined, for example: var slider = { init:function(data){ var fish = data. Fish || "default value"; } } Or you can make an "extend" function, to merge two objects, similar to the jQuery extend function: function extend (obj1, obj2) { var result = obj1, val; for (val in obj2) { if (obj2. HasOwnProperty(val)) { resultval = obj2val; } } return result; } var defaults = {val1: 1, val3: 3, fish: 'fish'}; extend(defaults, {val2: 2}); // returns Object val1=1 val3=3 fish=fish val2=2.

1 This is very good concept, I had no idea that you could do this, thanks. – Vnuk Sep 6 '09 at 19:32 lol, thanks - I was thinking about something like that but just couldn't put my finger on it - I also thought that it might throw errors because data. Fish would be null and it wouldn't want to be compared – j3frea Sep 6 '09 at 19:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions