<script type="text/javascript">
var ar = [];
ar["index"].push("data1");
ar["index"].push("data2");
ar["index3"].push("data5");
ar[55].push("data7");
console.log(ar);
</script>
I get: TypeError: ar.index is undefined
<script type="text/javascript">
var ar = [];
ar["index"].push("data1");
ar["index"].push("data2");
ar["index3"].push("data5");
ar[55].push("data7");
console.log(ar);
</script>
I get: TypeError: ar.index is undefined
with this
ar["index"].push("data1");
javascript tries to push "data1" into an array. The problem is that it expects an array, which ar["index"] is not as it is undefined.
You first need to initialize it
ar["index"] = [];
ar["index"].push("data1");
push() documentation here
Try this :-
<script type="text/javascript">
var ar = [];
ar["index"] = data1;
ar["index"] = data2;
.........
........
console.log(ar);
</script>
ar.length will still be 0 after your assignment. Array is just a special case of an object. If you do not use any of the added methods, just use a plain object.just make it like
<script type="text/javascript">
var ar = [];
ar.push("data1");
ar.push("data2");
ar.push("data5");
ar.push("data7");
console.log(ar);
</script>
Here is dev reference api => link
all_line_path[data.line_id] should return array.