Pradip Shenolkar
asked on
How to get element at particular position from javascript array ?
I have a array in javascript
Is there any function to achieve this ?
i want something which behaves like ArrayList.get() function in java.
var cars=["BMW","Mercedes","Audi"];
i want to get the element at particular position from this array.Is there any function to achieve this ?
i want something which behaves like ArrayList.get() function in java.
arraylist_name.get(2);
Off-course I can't use cars[0],cars[1].... etc.
ASKER
My requirements are such that I can't use cars[0], cars[1] etc
Is there any inbuilt function to do so ?
Is there any inbuilt function to do so ?
Nope... that is how you access arrays in javascript, what makes you think otherwise? What are you trying to do that makes you have to try and access an array like this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
console.log(cars[0]); // outputs "BMW"
console.log(cars[1]); // outputs "Mercedes"
console.log(cars[2]); // outputs "Audi"
my article touches on some of this stuff: https://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_13138-Javascript-is-just-an-Object.html