back to Overview

.toObject()

Creates an object map from a list of keys and a single values.
Util module only.

Syntax Variants

list.toObject(value)
_.toObject(keyList, value)

Parameters

keyList
A list or array to use for the keys of the new object.
value
the value to use
(return value)
the new object

Description

Creates an object map from a list of keys and a single values. toObject() goes through all values of the key list and adds a property with this key and the given a value.

Example

Create a simple object map:

 var map = _.toObject(['a', 'b', 'c'], 1);  // creates {a:1, b:1, c:1}

Example

Same result, but with a list method:

 var map = _('a', 'b', 'c').toObject(1);  // creates {a:1, b:1, c:1}

Comments

comments powered by Disqus

back to Overview

Functions