Skip to content

Instantly share code, notes, and snippets.

@gthrm
Created October 17, 2019 11:37
Show Gist options
  • Save gthrm/68b5de393e33dad7c6a19b79c7340f23 to your computer and use it in GitHub Desktop.
Save gthrm/68b5de393e33dad7c6a19b79c7340f23 to your computer and use it in GitHub Desktop.
Создает массив из одинаковых объектов с уникальным id по указанной длине
export const createContactsArray = (keys, values, len) => {
let i, arr = []
for (i = 1; i <= len; i++) {
let obj = {}
for (let index = 0; index < keys.length; index++) {
obj[keys[index]] = keys[index] === 'id' ? `00${i + index}` : values[index]
}
arr.push(obj);
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment