Upgrade plugin from API 1 to API 2

Hi,
With Photoshop 23 I am upgrading my Tools plugin to API 2.
Many of my “get” functions are rejected reading result[0].xxxxxx as undefined.

I have included an example which worked with API 1.
So, what did I miss?

const batchPlay = require("photoshop").action.batchPlay;
const app = require('photoshop').app;
const UXP = require("uxp");
const fs = require('fs');
const fs1 = require("uxp").storage.localFileSystem;
var exeModal = require('photoshop').core.executeAsModal;

async function getActiveLayeritemIndex (myName) {
 await exeModal(() => {
const result = batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "itemIndex"
         },
         {
            "_ref": "layer",
            "_name" : myName
         },
         {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": true,
   "modalBehavior": "execute"
 });})
const myItemIndex = result[0].itemIndex;
console.log(myItemIndex);
return myItemIndex;
}

I am not sure. I just tested this:

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "get",
      _target: [
         {
            _property: "itemIndex"
         },
         {
            _ref: "layer",
            _id: 4
         },
         {
            _ref: "document",
            _id: 677
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});
const pinned = result[0].itemIndex;

With IDs in references and it just worked. Manifest v5 API V2 PS v23.0

I must have wrongly express myself

I tried it with API 2 with result undefined.
I then tried it with API 1 with satisfying results since your script is asking the index of the layer indexed 4.

What I need to do is get the index of the layer by it’s name under API 2 without getting “undefined result”.

Even if the batchPlay works my results are always undefined.
So, my question is: How to formulate my 35 scripts to get the results I need under API 2

app.activeDocument.activeLayers[0]._id //returns active layer index

app.activeDocument.activeLayers[0].name // returns active layer name

Is this what you mean

Thank you so much Ian, this is exactly what I am looking fore.