0

I have a number in my application value is 6,

by using this value i have to create an array of [1, 2, 3, 4, 5, 6] using javascript/typescript

i have tried this in my application

 this.builder.group({
          'staff': this.builder.group({
          staff: [false],
          id: [this.staffData[i].users[j].id],
          labelName: [this.staffData[i].users[j].name],
          controlname: ['staff'],
          cssclass: ['error'],
          checked: [false],
          customcss: ['test1'],
          dayid: this.selectedDay,
          number: Array(this.appointmentsData.numberofSlots).fill().map((x,i) => i)})
})

but i am getting number as 0 in browser console. in VSCode also it is showing excepted 1-3 arguments but got 0 (i think it is for fill() method as i am passing 0 values , but i am unable to understand what to pass for fill() arguments) please help me

Sanoj_V
  • 2,936
  • 1
  • 12
  • 28
Santhosh
  • 1,053
  • 1
  • 20
  • 45

1 Answers1

0
Array.apply(null, {length: N}).map(Number.call, Number)
  • Thanks @Tomas, will try and let you know – Santhosh May 23 '18 at 12:13
  • it is throwing below error core.js:1440 ERROR TypeError: this.validator is not a function at FormControl.AbstractControl._runValidator (forms.js:3433) at FormControl.AbstractControl.updateValueAndValidity (forms.js:3387) at new FormControl (forms.js:3905) at FormBuilder.control (forms.js:7905) at FormBuilder._createControl (forms.js:7971) at eval (forms.js:7947) at Array.forEach () at FormBuilder._reduceControls (forms.js:7946) at FormBuilder.group (forms.js:7867) at AddStaffComponent.addStaffsGroup (add-staff.component.ts:129) – Santhosh May 23 '18 at 12:15
  • possible duplicate of [Create a JavaScript array containing 1…N](https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n?page=1&tab=votes#tab-top), where our friend Tomas found his answer : > – Adrien SAULNIER May 23 '18 at 12:25