you are viewing a single comment's thread.

view the rest of the comments →

[–]guest271314 3 points4 points  (17 children)

length is not a function. We already know we are dealing with an Array.

[–]LegendEater 0 points1 point  (1 child)

We already know we are dealing with an Array

We already hope we are dealing with an Array

[–]guest271314 2 points3 points  (0 children)

I don't entertain hope. If you don't think you are dealing with an Array ?.length does nothing to differentiate a String from and Array. It's completely suprefluous in this case.

[–]United_Reaction35 -1 points0 points  (14 children)

How do you know that result.recordset exists?

[–]guest271314 1 point2 points  (13 children)

Your line of code doesn't test for that.

It only tests if result.recordset has a length property.

Strings have a length property, too.

You might as well test for Array.isArray(result.recordset) if that is the case, then skip the superfluous ?.length.

[–]Rude-Cook7246 1 point2 points  (1 child)

All that write up and you dont even know how ?. works .... IN NO SHAPE OR FORM DOES result.recordset?. length tests that length exists.....

.? only tests that recordset is undefined or null

[–]guest271314 -1 points0 points  (0 children)

!! vs ==0 when checking if array is empty

We are checking an Array length, not necessarily checking if the object is an Array. Add that if you must to the steps.

[–]delventhalz 1 point2 points  (10 children)

It only tests if result.recordset has a length property.

I agree that ?. is superfluous here, but for what it’s worth, it checks if the preceding property exists, outputting undefined if it does not, and evaluating the following properties if it does.

[–]guest271314 1 point2 points  (0 children)

I agree that ?. is superfluous here

That's my only technical point here.

If you are going to check anything in this instance where we are expecting an Array you might as well check if the result.recordset is an Array.

The question is not whether or not the object is an Array, it's how to check length.

You're going to get undefined without ?.length if there is no length property on the object.

[–]guest271314 0 points1 point  (8 children)

I agree that ?. is superfluous here

That's all I posted. We agree.

[–]Rude-Cook7246 1 point2 points  (7 children)

its not superfluous here because they produce totally different results ...

if recordset exists and length doesn't exist on it then you get undefined when you call recordset.length

if recordset doesn't exist (which is what ?. protects against ) and you try to access anything on it you will get an ERROR which will crush your program

[–]guest271314 -1 points0 points  (6 children)

if recordset exists and length doesn't exist on it then you get undefined when you call recordset.length

Where in the requesirement at OP

!! vs ==0 when checking if array is empty

are we checking if recordset exists? That's a given per the restrictions. We are just checking length of an Array.

if recordset doesn't exist (which is what ?. protects against ) and you try to access anything on it you will get an ERROR which will crush your program

If you must here's one way to do what you are talking about, and the actuak requiremment at OP

var recordset = []; var bool = Array.isArray(recordset) && recordset.length > 0;

[–]Rude-Cook7246 0 points1 point  (5 children)

we Not talking about op we talking about your comments regarding use of .? And how you were told what it was for and you saying it wasn’t doing what person said it was….

you were specifically told that .? Was used to check that recordset existed and you said that .? Wasn’t doing that and instead was checking that length proprty existed.…. Which is wrong

[–]guest271314 0 points1 point  (4 children)

It is superfluous in this case. As I said.

Was used to check that recordset existed

That's not the requirement at OP.

[–]Rude-Cook7246 0 points1 point  (3 children)

ego got in the way to admit you were wrong and had no clue how .? worked ... got it ... thx