Can't access values

Hello.
I have database with 2 columns. Code and Project. I want to warn the user when he enters a code that exists with an alert box.

So, in my php page I am using the selected values from the database like this:

$sql = 'SELECT code FROM `projects`';
$stmt = $conn >prepare($sql);
$stmt -> execute([]);
$existingCodes = $stmt -> fetchAll (); //setting is FETCH_OBJ

Then, in javascript I am using this:

var occupiedCodes = <?php echo json_encode($existingCodes); ?>;

I can access each value by typing occupiedCodes[number].code but now I need a function to check if the code exists or not. I used typeof to see what kind of value occupiedCodes is and it returns an “object”.

I tried the following codes, but with no success:
Object.values(occupiedCodes).code
if (occupiedCodes.hasOwnProperty(“code example”) == true) {

Of course, I could use a for loop and it will work. But is there any simplest way?

If I use a for loop can I have memory usage problems? In the end there will be about 3000 to 6000 codes.

Thank you

Not sure I fully understand, but try this:

const isOccupied = Object.values(occupiedCodes).includes(code)

No. Returns False and it should return true. I wrote this cod and it works:

        for (var i= 0; i < occupiedCodes.length; i++){
            if  (occupiedCodes.length[i].code == projectCode.value) {
            e.preventDefault();
            alert('Code exists.');
          }
        }

This is ok. But I am afraid of memory issues. And maybe there is a faster way, regarding the computing of the code.

So occupiedCodes is an array not an object?
Then this may work:

const isOccupied = !!occupiedCodes.find(({code}) => code == projectCode.value)