Skip to content

Instantly share code, notes, and snippets.

@emersondemetrio
Created October 22, 2018 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersondemetrio/ffa89f110e70b88aee5a892ff243edab to your computer and use it in GitHub Desktop.
Save emersondemetrio/ffa89f110e70b88aee5a892ff243edab to your computer and use it in GitHub Desktop.
Replicate Object
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