JQuery iterates over an object using $ .each

I have an object options:options = {title : 'title1', name : 'name1', url : 'url1', etc.}

which is passed as a function parameter. I am trying to iterate over this object, pass it through another function evaluateand save the result in another object opts, for example:

var opts = new Object();

$.each(options, function(key,value){
opts.key = evaluate(element, value);
});

evaluate(element,value)works fine, but the problem is that it optslooks like this:

{key : eval(element,url1)}

instead

{title : eval(element,title1), name : eval(element,name1), etc.}

That is, it keyis transmitted literally instead of being evaluated, and is overwritten by each iteration with the last property in options.

Do I have the correct syntax in my target string? I also tried:

opts = {key : eval(element,val)}

, . $.each. , . - , .

( jQuery, Firebug Firefox).

.

+2
1

, "":

opts.key = evaluate(element, value);

[]:

opts[key] = evaluate(element, value);

:

var o = {};
o["test"] = "foo";
alert(o.test);
+8

Source: https://habr.com/ru/post/1725580/


All Articles