Home Discussion Discuss: JavaScript array position

  • Can do betterBrokenclock December 6, 2011 at 7:21 PM

    Well, your code does not work if you have an indexed array where some index are missing... For exemple, with the array {4: "Cat",5: "Dog",7: "Lion"} your fonction will never return the actual position of the seached item but only its index. You should better use the for...in statement like this : function getPosition(arrayName,arrayItem){ var i=0; for (item in arrayName){ if (item==arrayItem) return i; i++; } } Well, this function return 0 for the first position, as usual.

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
General

JavaScript array position
JavaScript array position     ... the position of the array items. There is not any built in method in the JavaScript...; <title> JavaScript array position example </title> < 

Programming Tutorials

Find position of an array element
Find position of an array element In this section, you will learn how to find the index of an array element. For this, we have allowed the user to enter... the position of the given integer in array. If the given integer is not in the array 

Java Beginners

How to put text file numbers to array and check the position of numbers?
How to put text file numbers to array and check the position of numbers?   I have numbers in text file data.txt 12 9 8 3 1 

Java Beginners

using array
using array  Circular left shift array element by one position 

Java Beginners

using array
using array  Circular left shift array element by one position 

JavaScript Questions

position of a link
position of a link  I have 10 links which links to a table if i click... position of a link the table appears at the bottom i want it to be display at the top pls help me.Each link if i click it should display in the same position 

General

JavaScript array get elements at random
index position:        javascript_array_random.html... JavaScript array get elements at random       In this example of getting JavaScript array 

Java Beginners

java array
, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds to the price of the fruit at the same position in the first list) i. e. if inputs 

General

JavaScript array slice
JavaScript array slice       JavaScript array class's slice() method returns the selected items... the starting index position. It does not modify the length of the array. Here 

Mobile Applications Questions

uitableviewcell delete button position
uitableviewcell delete button position  uitableviewcell delete button position - how can i set? Thanks in Advance 

Java-Tutorials

JavaScript array index of
print the index position of India on array. JavaScript_array_indexof.html...JavaScript array index of  In this Tutorial we want to describe that makes you to easy to understand JavaScript array index of. We are using JavaScript 

General

Array to Collection
Array to Collection       In this example we are converting values of an array into collection... at the next position is found then returns true otherwise throws an exception 

PHP Questions

in_array
in_array  in_array in php 

PHP Questions

is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array 

PHP Questions

is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array 

PHP Tutorial

php array append
append function is used to add the element in the last position of the array It adds the element to the array created by the ArrayObject class Example of PHP Array Append Function <?php $ar1=new ArrayObject 

Java-Tutorials

Finding an Element in a Sorted Array
that. And it show the given text position in the array, if text is present... in the array and returned value is the position of the text in the array otherwise... Finding an Element in a Sorted Array    

XML Questions

How to get the position of the comments in the pdf
How to get the position of the comments in the pdf  how to get the postion of comments, in the extracted xml, from pdf 

JavaScript Questions

How to get the position of the comments in the pdf
How to get the position of the comments in the pdf  how to get the postion of comments, in the extracted xml, from pdf 

PHP Tutorial

PHP Array Search
PHP Array Search In PHP, array_search() function performs a search  for a value in an array, as with in_array(). If the value is found then the index position of that key (which could be string or number) will be returned 

Java Beginners

Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array 

Java Beginners

return the position of last occurrence of an element
return the position of last occurrence of an element  A method " findLast(E element) " returns the position of the last occurrence of the given element. If this element is not in the list, then the null reference should 

Java Beginners

return the position of last occurrence of an element
return the position of last occurrence of an element  A method " findLast(E element) " returns the position of the last occurrence of the given element. If this element is not in the list, then the null reference should 

Java Beginners

Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array 

Programming Tutorials

SQL Add Column Position
SQL Add Column Position       SQL Add Column Position is used to add the column at the specific position. The Alter statement copy the structure of existed table and make a modify 

General

JavaScript Array
JavaScript array position In this section of JavaScript... JavaScript Array       JavaScript array print In the JavaScript array 

Java Beginners

Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements 

Programming Tutorials

jQuery UI Utility : Position
jQuery UI Utility : Position       jQuery UI Utility : Position The position utility script is used for positioning any widget relative 

PHP Tutorial

PHP Array Push
at last position (Last In First Out).  Example 1: <?php $array...PHP array push In this tutorial we will discuss about the different techniques to add item into an arrayarray_push() is one of the widely used 

Framework Questions

array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1 

DMCA.com