how to push multi values to array from single string in javascript?

I have a div under this ID “DivMarkers”,which contains the values below :

["first Project","29.3619524","47.922233","4","1","Complated","green"," "],
["Second Project","29.3619524","47.922233","4","1","Complated","green"," "],
["Third Project","29.3619524","47.922233","4","1","Complated","green"," "]

and I am trying to push each line as an Array item to my array which is markers1

I need to make this using pure javascript without jQuery, I have tried this but it did not work :

var values = (document.getElementById('<%= Markers.ClientID %>').innerHTML);

markers1.prototype.push.apply(Array, values);

any suggestions to fix this? or can I just convert the upper string to Multidimensional Array?

2 Answers

assuming that its containing a string, you do

let array = document.querySelector("#divId").innerHTML.split("n")

.split("n") will return an array containing every new line

I have solved it, using the below two lines :

var values = (document.getElementById('<%= Markers.ClientID %>').innerHTML);
markers1 = JSON.parse("[" + values +"]");

Thanks, everyone for your help

Archive from:

Leave a Reply

Your email address will not be published. Required fields are marked *