Avatar of Pradip Shenolkar
Pradip Shenolkar
Flag for India asked on

How to get element at particular position from javascript array ?

I have a array in javascript
var cars=["BMW","Mercedes","Audi"];

Open in new window

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);

Open in new window

Off-course I can't use cars[0],cars[1].... etc.
JavaScriptJava

Avatar of undefined
Last Comment
Pradip Shenolkar

8/22/2022 - Mon
Rob

var cars=["BMW","Mercedes","Audi"];

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
Pradip Shenolkar

ASKER
My requirements are such that I can't use cars[0], cars[1] etc
Is there any inbuilt function to do so ?
Rob

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?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Rob

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pradip Shenolkar

ASKER
thanks