I'm working with an array in my Angular application, for example:
searchTerm : any[]
In the context of a textbox value like {'state':'tn'}, I'd like to push this to the searchTerm array. Currently, I achieve this by adding the item to a service and then the array as follows:
private onItemAdded(event): void {
const filter = JSON.parse('"' + event['value'] + '"');
this.dataService.addFilter(filter);
}
However, the stored result is "{'state':'tn'}"
How can I parse this without having double quotes at the beginning?
console.log('ADDED FILTER', event['value']);
The printed value here is {'state':'value'}
But when assigned to a variable as below, it ends up with added double quotes:
let filter = event['value'];
Thank you.