10 examples of 'lodash array to object' in JavaScript

Every line of 'lodash array to object' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
5function objectToArray(object) {
6 return object.arr;
7}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

872function arrayToObject(arr, getKey, getValue) {
873 return arr.reduce(function(acc, val) {
874 acc[getKey(val)] = getValue(val);
875 return acc;
876 }, {});
877}
118export function toArray(obj: any): any[] {
119 if (isNone(obj)) {
120 return [];
121 } else {
122 return Array.isArray(obj) ? obj : [obj];
123 }
124}
58function arrayToObject(array) {
59 return Object.assign(...array.map(([key, value]) => ({ [key]: value })));
60}
9function arrayify(o) {
10 if (Array.isArray(o)) {
11 return o;
12 } else {
13 return [o];
14 }
15}
6function arrayify (o) {
7 if (Array.isArray(o)) {
8 return o
9 } else {
10 return [o]
11 }
12}
9export function toArray(v?: any): Array<any> {
10 if (isArray(v) || isUndefined(v) || isNull(v)) {
11 return v;
12 }
13 else {
14 return [v];
15 }
16}
307function objectify(value) {
308 if (typeof value === 'string') {
309 return {
310 task: value
311 };
312 }
313 if (typeof value === 'function') {
314 return {
315 task: value
316 };
317 }
318 if (_.isPlainObject(value)) {
319 return value;
320 }
321 // array etc.
322 return {
323 task: value
324 };
325}
1export function arrayify<T>(obj: T | T[]): T[] {
2 return Array.isArray(obj) ? obj : [obj];
3}
14function isArray(o) {
15 return Object.prototype.toString.call(o) === '[object Array]';
16}

Related snippets