#6191·lodash

cloneDeep wrongly applies <undefined> value to weak array elements; should stay <empty>!

Author: ralphwetzelCreated Apr 9, 2026Updated Jul 12, 2026
Labelsbug

There's evidence that _.cloneDeep wrongly applies undefined to empty array elements:

javascript
import * as _ from 'lodash';

// create a weak array, just fill index 3:
let x = new Array(5);
x[3] = 42;

console.log("Original array:")
x.forEach( (xx, i) => console.log(`${i}: ${xx}`));
console.log("");

console.log("Array after _.cloneDeep:")
let y = _.cloneDeep(x);
y.forEach( (xx, i) => console.log(`${i}: ${xx}`));
console.log("");

console.log("Array after structuredClone:")
let z = structuredClone(x);
z.forEach( (xx, i) => console.log(`${i}: ${xx}`));

output:

Image

There was a pull request (in 2023) to address this issue - yet is was not merged, but closed and labeled issue bankruptcy.