I have a large (~10,000 items) object of objects read from a JSON file and stored as a local variable, in a format something like this:
{
"some_uuid_1" : {"code":"some_code_1", "name":"asdf"},
"some_uuid_2" : {"code":"some_code_2", "name":"qwer"},
...
"some_uuid_n" : {"code":"some_code_n", "name":"zxcv"}
}
I'd like to iterate through the entire main object, compare each element's name
property to some variable checkName
, and append the element's code
property to a DOM element if there is a match, as such:
function myFilter(checkName)
{
var myArray = Object.values(myObj);
for (var i = 0; i < myArray.length; i++)
{
if (myArray[i]["name"] == checkName)
{
$("#someElement").append(`${myArray[i]["code"]} <br />`);
}
}
}
However, as the size of the object is quite large, I'd like to run the function asynchronously so that it doesn't freeze up the browser while it's running. I don't mind if the DOM element #someElement
is slowly populated in the background while other code runs.
How may I accomplish this using JavaScript and/or JQuery?