i new underscore js, trying omit property on object. did was
myobj = _.omit(myobj,name) console.log(myobj); still myobj seems have property name. although if seemes work
newmyobj= _.omit(myobj,name) console.log (newmyobj) it seemed work fine. doing wrong, can help? ok, myobj looks this
angola: "4.134137685",brunei: "2.532726835",countries: "2004",croatia: "1.717672961", keys: array[11] i trying omit "keys" again array of objects
thanks
there these things called "debuggers". if don't know are, stop you're doing , learn them now. search google "chrome devtools", instance. stop code (put breakpoint) @ point before call _.omit. in console, type in myobj see contains, name. or, use 'scope variables" section of devtools check value of these variables. now, make single step (f10). see if or how variables have changed, or type myobj again console check value.
in particular case, report deletion of property occurs when
newmyobj= _.omit(myobj,name) but not with
myobj= _.omit(myobj,name) in , of itself, behavior unexplainable. there's else going on you're not telling about. guess doing this:
myobj = { keys: [] }; name = "keys"; delete_property(); console.log(myobj.keys); // [] function delete_property(myobj) { myobj = _.omit (myobj, name); } however, not might think. assignment myobj within function nothing; reassigns value of function argument. has no effect on myobj outside function.
to sure, we'd need see more of actual code, regular old debugging problem of sort encounter thousands of times in programming career, you're better off learning solve yourself.
Comments
Post a Comment