Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace 1 for true in jQuery object

Tags:

jquery

I have an object which gets passed to a function as such:

function(config['options'])

There are certain values in here such as config['options']['property1'] which are set as 1, which I want to change to true (like wise 0 to false) before they get passed to this function.

How do I go about doing this, I can't seem to figure it using .each()

like image 220
Rick Donohoe Avatar asked Jan 13 '23 05:01

Rick Donohoe


1 Answers

options is an object, so use a for-in loop to iterate the properties:

for (var key in config.options) {
    var current = config.options[key];

    if (current === 1) {
        config.options[key] = true;
    }

    if (current === 0) {
        config.options[key] = false;
    }
}
like image 62
jbabey Avatar answered Jan 22 '23 00:01

jbabey