Struggling to figure out how to create an associative array in Angular2?
I've attempted the following:
onSubmit(){
let inputfield:any[] = [];
for(var i=0; i<this.inspectionform.value["inputfileds"].length; i++){
if(this.inspectionform.value["inputfileds"][i]["input"] != ""){
//need help here
inputfield.push( i : this.inspectionform.value["inputfileds"][i]["input"]) //syntax error returned
}
}
} What I actually want is to add a key and value pair to the array
Something like
1:sdbhd //add this to the array
In my attempts within the for loop, I've tried:
//inside the for loop
let arrayval = [];
arrayval.push(this.inspectionform.value["inputfileds"][i]["input"])
arrayval.push(i)
inputfield.push(arrayval);
This results in a new object of this type being created each time:
0:njnf
1:1(value of i)