0

I have got the data as [0:1,1:2,2:3] here 0,1,2 at the left side is array index but i dont want this data format i want it as ['1','2','3'] as a string.
Here's my code

onChange(categoryId: string, isChecked: boolean) {
  debugger
  const categoryIdArray = (this.patientReportForm.controls.hubxCategoryId) as FormArray;
  
  if (isChecked) {
    categoryIdArray.push(new FormControl(categoryId));
  } else {
    let index = categoryIdArray.controls.findIndex(x => x.value == categoryId)
    categoryIdArray.removeAt(index);
  }
}

in categoryIdArray i tried to use join function as

categoryIdArray.join(",")

here i got an error - Property 'join' does not exist on type 'FormArray'

this is my formcontrol

this.patientReportForm = this.formBuilder.group({
      patientId : new FormControl(Number(this.clientId)),
      hubxCategoryId : this.formBuilder.array([]),
      notes : new FormControl(),
    })

1 Answer 1

3

Assuming your input also be an array of strings, we can try using map() here along with split():

var input = ["0:1", "1:2", "2:3"];
var output = input.map(x => x.split(":")[1]);
console.log(output);

Sign up to request clarification or add additional context in comments.

2 Comments

my input is not ["0:1", "1:2", "2:3"]; here 0,1,2 is array index and the data i got is 1,2,3
is there any alternative way to achieve it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.