This is driving me absolutely nuts being a beginner JavaScript meddler.
I have an array called arrayA with the following data (in my actual code I declare arrayA with [] and then use $.getJSON to ingest a file that contains data):
arrayA = [
{
"Key": "Key1",
"Value": {
"info1": "298431",
"info2": "55.035",
"info3": "11.375",
},
"Name": "Key1"
}
]
In my HTML page, I have a script tag/section and this is defined there. After arrayA, I have a function called funcA() where I try and do "stuff" This includes things like finding the index for "Key1" as an example.
When doing console.log in line it always reports as 0 but when checking the length using Chrome's console it reports the correct number of objects (8950).
Not really sure what is the problem. Potentially variable scoping or the way the arrayA is initialised and loaded with data? Could someone help?
For completeness:
<script type="text/javascript">
var arrayA = [];
$.getJSON('./source.json', function(data) {
arrayA = data;
});
function funcA() {
//Do stuff to find indexOf "Key1"
}
</script>
/D