-2

I am using Tampermonkey for writing scripts. Before i was using AUTOIT, and there was a function like "If is array then". Is there any option like this in JavaScript?

The main command is

>     setTimeout(function (){
> 
> document.querySelector('[value="Click"]').click();
> 
>     }, 999);

I want to click in that class(and more)

<div class="center" onclick="58246246.submit()" style="cursor: pointer;">

I try something like that but it doesn't work, script is clicking in first value

if ($("center")[0]){
setTimeout(function (){
$1(function(){
document.getElementsByClassName("center")[0].click();
        }, 999);

Can someone help me?

Melchia
  • 22,578
  • 22
  • 103
  • 117
  • 4
    [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) checks for array. – Hassan Imam Jan 30 '18 at 12:24
  • 5
    Possible duplicate of [Check if object is array?](https://stackoverflow.com/questions/4775722/check-if-object-is-array) – Anonymoose Jan 30 '18 at 12:26
  • `a function like "If is array then". Is there any option like this in javascript` - Yes and if you google for `how to check if is array in JavaScript` you find an answer very very very quickly. – Nope Jan 30 '18 at 12:29

2 Answers2

0

Array.isArray(object) is what you're looking for. It returns true if the object is an array, false otherwise. Checking the documentation you can see exactly what the limits to this are (for example, Array.prototype is an array).

jon1467
  • 89
  • 2
  • 7
0

you can use Array.isArray(array_name);

if(Array.isArray(array_name){
    if ($("center")[0]){
        setTimeout(function (){
            $1(function(){
                document.getElementsByClassName("center")[0].click();
            }, 999);
}
Abhishek Anand
  • 447
  • 5
  • 22