find a value in a grid

I need to search a grid to ensure that each value in the items string is in the grid and if one item isn’t in the grid show an alert.

var items = “1,2,3”;

my grid is setup as:
item name
1 me
2 you
3 we

how would I go about doing that? Is the code below the right approach?

var index;
var items = “1,2,3”;
items = items.replace(/,/g, ‘’);
var cellValue = “”;

for (var i=0; i<mygrid.getColumnCount(); i++){
cellValue = mygrid.CellById(row_id,i).getValue();

for (index = 0; index < items.length; ++index) {
if(cellValue != items[index]) {
alert(“Error”);
}
}
}

You need to iterate through all the rows of your grid:
mygrid.forEachRow(function(id) {
cellValue = mygrid.CellById(id,0).getValue();
for (index = 0; index < items.length; ++index) {
if(cellValue != items[index]) {
alert(“Error”);
}
}
});

how do i call this code as I can’t get into the code. i have a button that does the following:

$("#submit").click(function () {
validateGrid();

//other code
});

function validateGrid() {
var index;
var items = groups; //“1,2,3”;
var cellValue = “”;

    gridbox.forEachRow(function(id) {
alert("entering gridbox function");
        cellValue = gridbox.CellById(id,0).getValue();
        
        for (index = 0; index < items.length; ++index) {
            if(cellValue != items[index]) {
                alert("Error");
            }
            else {
                alert("Good");
                }
        }
   });

}

the code enters the validateGrid but never enters the gridbox.forEachRow.

Please, make sure that the gridbox is a global variable.

Now with: gridbox.forEachRow(function(id) {

i get:
Uncaught TypeError: gridbox.forEachRow is not a function

Please, share with a demo link, or provide with a complete demo, where the problem can be reconstructed locally.