Reputation: 7
I have array with values like this
arr = [ 'java', 6 ]
My question, is how do I get just "java" in my output
My output should be like
java
Upvotes: 0
Views: 187
Reputation: 141
Javascript arrays are have their indexes start at 0.
So, arr = [ 'java', 6 ]
contains 2 elements. And since arrays have their index start at 0, 'java' would be at the [0] index and '6' would be at the [1] index.
To access it you just need to do arr[0] and output it with, for example, console.log(arr[0])
which is the simplest way to access 'java'. (e.g You can do arr[i] where i is a number with a value of 0)
Upvotes: 0
Reputation: 65
if you want you output java this is sol :
var arr = [ 'java', 6 ];
alert(arr[0]);
Upvotes: 0
Reputation: 2429
Use indexing; 0 for 'java', and 1 for 6.
To get 'java'
, just do arr[0]
Upvotes: 1