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