I have an array with data that looks like this.
var objects = [
{
"rowid": 1,
"Hostname": "11 Com"
},
{
"rowid": 2,
"Hostname": "11 UMi"
},
{
"rowid": 3,
"Hostname": "14 And"
},
{
"rowid": 5,
"Hostname": "23 A"
}];
I'm trying to get the position of the element number of each object. Each object consists of their own "row id" and that's basically what I'm currently using to retrieve their element position with this function:
function findCorrespondingNumber(hostname) {
function search(am, im) {
if (am.Hostname === hostname) {
index = im; return true; }
} var index;
if (objects.some(search)) {
return objects[index]['rowid'];
}
}
var correspNumb = findCorrespondingNumber(name) - 1;
var fiff = objects[correspNumb]["Hostname"];
The problem with the dataset is that numbers can sometimes skip sequence. The rowid 3 is followed by 5, instead of 4 as it should be. This is causing problem with further code so I need to have it so that the object with rowid 5 is read as the fourth object. How would I write that code?