atoo

2025.4.17 • Public • Published

atoo: array to object

Convert any array to object with/without given key-prefix.

npm install atoo

This package: github | npm

Also see: otoa: github | npm

Usage

// var {arrayToObject} = require('atoo');
import {arrayToObject} from "atoo";
const obj = arrayToObject(array [, keyPrefix]);
arrayToObject([1, 2, 3, "a", , , , "b"], "i-");
// Object {i-0: 1, i-1: 2, i-2: 3, i-3: "a", i-7: "b"}

arrayToObject([1, 2, 3, "a", , , , "b"]);
// Object {0: 1, 1: 2, 2: 3, 3: "a", 7: "b"}

Note: Takes care of sparse arrays too.

License

The MIT License (MIT)

Copyright (c) 2016-2025 Anubhav Saini

Package Sidebar

Install

npm i atoo

Weekly Downloads

22

Version

2025.4.17

License

MIT

Unpacked Size

19.2 kB

Total Files

10

Last publish

Collaborators

  • iamanubhavsaini
  • git.faf
  • anusaini