How to use strings as array indexes using javascript?



How to use strings as array indexes using javascript?..

Answer / Animesh Khare

In JavaScript, you can use strings as array indexes by treating the array like an object and accessing its properties. Here's an example: nn```javascriptnlet myArray = {'apple': 1, 'banana': 2, 'cherry': 3};nconsole.log(myArray['apple']); // Outputs: 1```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

Describe the properties of an anonymous function in JavaScript?

1 Answers  


write a program using javascript/ vbscript that checks if two matrices have identical values in all the elements.

1 Answers  


What is a named function in JavaScript? How to define a named function?

1 Answers  


What is an object in javascript, give an example?

1 Answers  


Which is better python or javascript?

1 Answers  


How to convert a string to lowercase?

1 Answers  


Which keyword is used to print the text in the screen?

1 Answers  


What is the use of a typedarray object in javascript?

1 Answers  


What is spread operator react?

1 Answers  


How to capture the Image width and height using QTP script ? Kindly answer plz.... Thanx in adavance...

1 Answers  


What is emotional closure?

1 Answers  


What makes a relation a function?

1 Answers  


Categories