Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a variable is an Array

Tags:

grails

groovy

I want to find out whether a variable is an array or not

  if (params.writtenLines == ???)

Much appreciated.

like image 923
WaZ Avatar asked Jun 01 '10 14:06

WaZ


People also ask

How do you check whether an variable is an array in JS?

The Array. isArray() method checks whether the passed variable is array or not. If the variable is an array it displays true else displays false.

How do I check if a variable is an array in TypeScript?

You can use the Array. isArray method to check if a value is an array in TypeScript. Copied! The method takes a value as a parameter and returns a boolean result - true if the value is an array and false otherwise.

How do you check if a variable is in an array Python?

To check if an array contains an element or not in Python, use the in operator. The in operator checks whether a specified element is an integral element of a sequence like string, array, list, tuple, etc.

Can a variable be an array?

An array is a variable containing multiple values. Any variable may be used as an array. There is no maximum limit to the size of an array, nor any requirement that member variables be indexed or assigned contiguously.


1 Answers

More importantly, why do you want to check whether it's an array? If you know the parameter might be a single string or a list, you can now use:

def lines = params.list("writtenLines")

That came with Grails 1.2.

like image 82
Peter Ledbrook Avatar answered Sep 20 '22 19:09

Peter Ledbrook