0
events: "[{id:"3",title:"activity",start:"2017-03-11 00:00:00",allDay:true},{id:"4",title:"nutrition",start:"2017-03-11 00:00:00",allDay:true}]"

how can I remove the quote or pass this string as normal array in angularjs2?

Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52

3 Answers3

2

It's a JSON string. just use JSON.parse and you'll get array of objects.

cymruu
  • 2,808
  • 2
  • 11
  • 23
0

Here, the string in events object is not a valid JSON. So u can't use JSON.Parse here. For valid JSON key should be wrapped in double quote eg: {id:...} should be {"id":...}

let input = {
     events: '[{id:"3",title:"activity",start:"2017-03-11 00:00:00",allDay:true},{id:"4",title:"nutrition",start:"2017-03-11 00:00:00",allDay:true}]'
};

let dataToSend = Object.assign({}, input);

dataToSend.events = eval(dataToSend.events);

console.log(dataToSend);

output

Since, your input sting is still a valid javascript object you can use eval method for conversion. Here I used object.assign to create a copy of your input. So, any modification to dataToSend will not affect your actual input object.

ajai Jothi
  • 2,284
  • 1
  • 8
  • 16
0

let input = {
     events: '[{id:"3",title:"activity",start:"2017-03-11 00:00:00",allDay:true},{id:"4",title:"nutrition",start:"2017-03-11 00:00:00",allDay:true}]'
};

eval(obj.events);

enter image description here

Sahil Gupta
  • 211
  • 3
  • 9