Skip to content

Create an object from an iterable of key/value-pairs

Notifications You must be signed in to change notification settings

LinusU/node-build-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Object

Create an object from an iterable of key/value-pairs.

Installation

npm install --save build-object

Usage

const buildObject = require('build-object')

const me = buildObject([
  ['firstName', 'Linus'],
  ['lastName', 'Unnebäck']
])

console.log(me)
// => { firstName: 'Linus', lastName: 'Unnebäck' }

API

buildObject(items) => object

Build an object from items.

items should be an iterable (e.g. an array) where each item is a key/value pair.

If the same key is specified twice, the latter will take precedence.

A TypeError will be thrown in the following conditions:

  • items is not an iterable
  • any element in items is not an object
  • any key is not a string

About

Create an object from an iterable of key/value-pairs

Resources

Stars

Watchers

Forks

Packages

No packages published