DEV Community

Discussion on: Four Ways to Clone Array with Ease! Easiest Method to Clone Array.

Collapse
 
davispindola profile image
Spindola • Edited

You can also:

const arr = [1, 2, 3]

// with map
const cloned_with_map = arr.map(i => i)

// with reduce + flat
const cloned_with_reduce = 
  arr.reduce((a, b) => [a, b])
  .flat()

Array.of(arr).flat()
Enter fullscreen mode Exit fullscreen mode

Obs.: both are bad practices.

😎

Collapse
 
hasnaindev profile image
Muhammad Hasnain • Edited

Hahaha, yes. I created this post for LinkedIn. Surprisingly, such posts get a lot more attention than posts that contains valuable information.

Collapse
 
davispindola profile image
Spindola • Edited

Linkedin is just facebook without so much trash today. hahaha

Thread Thread
 
hasnaindev profile image
Muhammad Hasnain

So true! xD