Skip to main content
dublove
Legend
July 18, 2025
Question

How to determine if a found object is empty?

  • July 18, 2025
  • 1 reply
  • 109 views

The code below, which I tested with alter,

The left popup is "empty". The right popup is  [objet charater].

 

This shows that there are  difference.    Since it is different, the choice can be judged.

 But when I use if(!qz===''),  It always prompts (!qz===‘’) with a result of false.

 

What do I have to write   "if (   )"  to get it right?

 

Another problem:
If an @ is found, and there is only one, also execute the subsequent code.
If the loop does not find an @, it prompts alert(“No one @”).

How  to write this?


Thank you very much.

 

    for (var h = 0, k = 0; h < sa.length; h++) {
        if ("TextFrame" == sa[h].constructor.name) {
            if (sa[h].overflows) {
                sa[h].fit(FitOptions.FRAME_TO_CONTENT)
            }
            //alert(sa[h]);
            var qz = getGrepSearch("@", sa[h]);
            alert(qz);
            alert((!qz === ''));
            //for (var k = 0; k < sa.length; k++) {
            if (qz === !"") {

 

 

1 reply

dublove
dubloveAuthor
Legend
July 19, 2025

Or I worked it out myself.
qz.length!==0

 

Still didn't think of it though:
How the same for can be split into two cases:
As soon as one is found, it is executed.
If one is not found, the prompt is: noOne;

 

Is this the only way I can do it? But then the focus I selected is lost.

if(found==0){
alert("no find")
}
else if(found>=0){
do someting
. . .
}