Hoslack
Hoslack

Reputation: 105

Search for element using index in javascript

['zero','one','two','three','four','five','six','seven','eight','nine'] I want to search for an element with index 4 in the array above. So 4 should return the word "four" because it is at index four. Please help.

Upvotes: 2

Views: 33

Answers (1)

Travis
Travis

Reputation: 12379

You would simply use bracket notation like so:

var array = ['zero','one','two','three','four','five','six','seven','eight','nine'];

console.log(array[4]);

The above snippet outputs 'four' to the console. For more information, see MDN's Property accessors page.

Upvotes: 2

Related Questions