1

I'm new in AWS AppSync. I just need to check if a variable is an array. I've already tried following ways but they are not working.

1. Array.isArray(variable)

I got an error when I run this code

This seems not to be supported according to this official document while other common Array's functions are clearly stated. https://docs.aws.amazon.com/appsync/latest/devguide/built-in-objects-functions.html

2. Using util.isList (@aws-appsync/utils)

This also doesn't work with this error

*'isList' does not exist on type 'Util'.*

This function looks like supported only in VTL version

https://docs.aws.amazon.com/appsync/latest/devguide/utility-helpers-in-util.html

Do anyone have any idea to check if variable is an array?

Komachi
  • 139
  • 4

1 Answers1

0

Went for this hacky solution, probably does not cover all use cases but worked for our scenarios:

function isArray(input) {
  return typeof input === "object" && input !== null && typeof input.length === "number";
}