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?

1 Answer 1

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";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.