JSFiddle - React, Tailwind, and code Playground

by NerfAnarchist

JavaScript

// prototyping
function wfprod_jo(JSONOBJ) {
    for (key in JSONOBJ) {
        this[key] = JSONOBJ[key];
    }
}
/* wfprod_jo can be replaced with Object */
wfprod_jo.prototype.key_num = function (key_number) {
    var i = 0, key, json_obj = this;
    
    for (key in json_obj) {
        if (i === key_number) {
            return this[key];
        } else {
            i = i + 1;
        }
    }
    return 'NO SUCH KEY';
}
    
wfprod_jo.prototype.key_for_num = function (key_number) {
    var i = 0, key, json_obj = this;
    
    for (key in json_obj) {
        if (i === key_number) {
            return key;
        } else {
            i = i + 1;
        }
    }
    return 'NO SUCH KEY';
}

wfprod_jo.prototype.jo_length = function () {
    var i = 0, key, json_obj = this;
    for (key in json_obj) {
        if (json_obj[key] !== wfprod_jo.prototype[key]) {
            i = i + 1;
        }
    }
    return i;
}

var testing = new wfprod_jo({'test':'asdf','tes':'world'});


//console.log('1', testing.key_for_num(1));
//console.log('2', testing.key_num(1));
//console.log('3', testing.jo_length());
console.log(testing);