Created
October 22, 2018 17:10
-
-
Save emersondemetrio/ffa89f110e70b88aee5a892ff243edab to your computer and use it in GitHub Desktop.
Replicate Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const replicateObject = (obj, times) => { | |
const tmp = JSON.stringify(obj); | |
return JSON.parse("[" + tmp.concat(",").repeat(times).slice(0, -1) + "]"); | |
}; | |
const example = { | |
n: 10, | |
prop1: "My Name", | |
prop2: "My Other Name" | |
}; | |
const test = replicateObject(example, 100); | |
console.log(test); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment