Is there a function for retrieving last array's element value?

csandreas1

I have an array of inputs that accepts a range of 0 and 1. var array = [0,1,0,0,1];//that is not static

Is there a function for retrieving the last element of the array?

function myfn(){
    var array = [1,0,0,0,1,0]; //that may change depending on the user inputs
    var b= 0;
    let l = array.length;
    for(b=0; b<l; b++)
        if(array [l-1]==0)
            document.getElementById('print').textContent = 'Last element is 0'; 

}//end function            

P.S: I am editing this old and bad question in order to get give the community time to re-evaluate it.

Tanmay Vats

Please try this

function myfn(){
    var array = [1,0,0,0,1,0]; //that may change depending on the user inputs
    var b=0;
    if(array[array.length-1] == 0)
        document.getElementById('print').textContent = 'Last element is 0';

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Retrieving an element of an array that is a value of a hash with Ruby

From Dev

ng-repeat nested array's last element to a function

From Dev

Find a document that contains a specific value in an array but not if it's the last element

From Dev

Find a document that contains a specific value in an array but not if it's the last element

From Dev

why shifting array with a push copies last value to second last element?

From Dev

PHP function only getting last value of array

From Dev

Component's onChange function being passed the last parameter value when the ReactJS components are rendered from an array

From Dev

Retrieving element number inside array

From Dev

Retrieving a value from a function in ngStyle

From Dev

Evaluate absolute value of array element in function

From Dev

Evaluate absolute value of array element in function

From Dev

How to compare the value of an array element passed to a function

From Dev

I must create a function, that returns the last element of an array that is passed in

From Dev

Sort documents by value in the last element of an array that matches filter. Mongodb

From Dev

Why is the function(s) not retrieving the data?

From Dev

Make array element copy it's previous element's value

From Dev

c# .net xml serialization retrieving value from xml element array

From Dev

Last element of an Array in Clojure

From Dev

Find the last element in an array

From Dev

Last element in array is nil

From Dev

The array is filling with the last element

From Dev

Fortran last element of the array

From Dev

Check last array element

From Java

What's the best way to get the last element of an array without deleting it?

From Dev

PHP: Get first and last element entries in array and it's keys

From Dev

Array is only printing the last stored value and array element removal only replaces element

From Dev

cost of retrieving an element from array in java

From Dev

Laravel retrieving element from input array

From Dev

Retrieving php array key and value from postgresql function parameter for database update

Related Related

  1. 1

    Retrieving an element of an array that is a value of a hash with Ruby

  2. 2

    ng-repeat nested array's last element to a function

  3. 3

    Find a document that contains a specific value in an array but not if it's the last element

  4. 4

    Find a document that contains a specific value in an array but not if it's the last element

  5. 5

    why shifting array with a push copies last value to second last element?

  6. 6

    PHP function only getting last value of array

  7. 7

    Component's onChange function being passed the last parameter value when the ReactJS components are rendered from an array

  8. 8

    Retrieving element number inside array

  9. 9

    Retrieving a value from a function in ngStyle

  10. 10

    Evaluate absolute value of array element in function

  11. 11

    Evaluate absolute value of array element in function

  12. 12

    How to compare the value of an array element passed to a function

  13. 13

    I must create a function, that returns the last element of an array that is passed in

  14. 14

    Sort documents by value in the last element of an array that matches filter. Mongodb

  15. 15

    Why is the function(s) not retrieving the data?

  16. 16

    Make array element copy it's previous element's value

  17. 17

    c# .net xml serialization retrieving value from xml element array

  18. 18

    Last element of an Array in Clojure

  19. 19

    Find the last element in an array

  20. 20

    Last element in array is nil

  21. 21

    The array is filling with the last element

  22. 22

    Fortran last element of the array

  23. 23

    Check last array element

  24. 24

    What's the best way to get the last element of an array without deleting it?

  25. 25

    PHP: Get first and last element entries in array and it's keys

  26. 26

    Array is only printing the last stored value and array element removal only replaces element

  27. 27

    cost of retrieving an element from array in java

  28. 28

    Laravel retrieving element from input array

  29. 29

    Retrieving php array key and value from postgresql function parameter for database update

HotTag

Archive