Table of Contents

About

Encodes a string of key-value pair from an array 'a' and returns a JavaScript object of keys and values.

Example Usage

When the function is called with:

var a = ['a', 'b', 'c', 'd'];
var test = wasKeyValueObjectify(a);

it will return the JavaScript object:

{"a":"b","c":"d"}

Code

JavaScript

/*************************************************************************/
/*    Copyright (C) 2017 Wizardry and Steamworks - License: CC BY 2.0    */
/*************************************************************************/
function wasKeyValueObjectify(a) {
    var o = {};
    a.reduce(function(a, c, i) {
        i = Math.floor(i / 2);
        if (!a[i]) {
            a[i] = [];
        }
        a[i].push(c);
        return a;
    }, []).forEach(function(c, i, a) {
        o[c[0]] = c[1];
    }, o);
    return o;
}

fuss/data_structures/key-value_pairs/javascript/to.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.