CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-concat

Creates a new array concatenating array with any additional arrays and/or values

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Lodash Concat

Lodash concat creates a new array concatenating an array with any additional arrays and/or values. This function provides a reliable way to combine arrays without mutating the original array, handling edge cases gracefully.

Package Information

  • Package Name: lodash
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash (concat is part of the main lodash library)

Core Imports

import { concat } from "lodash";

For CommonJS:

const { concat } = require("lodash");

Alternative global usage:

// If lodash is loaded globally
_.concat(array, ...values);

Basic Usage

import { concat } from "lodash";

// Basic concatenation
const array = [1];
const result = concat(array, 2, [3], [[4]]);
console.log(result);
// => [1, 2, 3, [4]]

// Original array is unchanged
console.log(array);
// => [1]

// Handling null/undefined input
const nullResult = concat(null, 1, 2);
console.log(nullResult);
// => [1, 2]

const undefinedResult = concat(undefined, 1, [2], [[3]]);
console.log(undefinedResult);
// => [1, 2, [3]]

// Non-array first parameter
const stringResult = concat("hello", " ", "world");
console.log(stringResult);
// => ["hello", " ", "world"]

Capabilities

Array Concatenation

Creates a new array by combining the input array with additional values, handling non-array inputs gracefully.

/**
 * Creates a new array concatenating array with any additional arrays and/or values.
 * @param {Array} array - The array to concatenate  
 * @param {...*} [values] - The values to concatenate
 * @returns {Array} Returns the new concatenated array
 */
function concat(array, ...values);

Behavior Details:

  • Immutable Operation: Never modifies the original array
  • Type Conversion: If array is not an array:
    • null or undefined becomes an empty array []
    • Other values become a single-element array [Object(value)]
  • Flattening: Values are flattened by one level only
  • Variable Arguments: Accepts any number of additional values after the first parameter
  • Sparse Arrays: Treats sparse arrays as dense arrays (undefined values are preserved)

Usage Examples:

import { concat } from "lodash";

// Multiple arrays and values
const arr1 = [1, 2];
const arr2 = [3, 4];
const result = concat(arr1, arr2, 5, [6, 7]);
console.log(result);
// => [1, 2, 3, 4, 5, 6, 7]

// Nested array handling (one level flattening)
const nested = concat([1], [[2, 3]], [[[4]]]);
console.log(nested);
// => [1, [2, 3], [[4]]]

// Empty array concatenation
const empty = concat([], 1, 2, 3);
console.log(empty);
// => [1, 2, 3]

// Mixed data types
const mixed = concat([1, 2], "hello", true, { key: "value" });
console.log(mixed);
// => [1, 2, "hello", true, { key: "value" }]

// Sparse arrays (treated as dense)
const sparse = concat(Array(2), Array(1));
console.log(sparse);
// => [undefined, undefined, undefined]
console.log('0' in sparse); // => true
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash@4.5.x#concat
Publish Source
CLI
Badge
tessl/npm-lodash-concat badge