0

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
3
  • Same as with most programming languages: arr[0] Commented Mar 11, 2017 at 8:35
  • 1
    Java and Javascript are about as similar to each other as Car and Carpet. Commented Mar 11, 2017 at 8:42
  • 1
    This question is trivial and can be solved by reading the most basic introductory article on JavaScript arrays. It is unlikely to help future users. Commented Mar 11, 2017 at 8:50

3 Answers 3

1

Use indexing; 0 for 'java', and 1 for 6. To get 'java', just do arr[0]

Sign up to request clarification or add additional context in comments.

Comments

0

if you want you output java this is sol :

var arr = [ 'java', 6 ];
alert(arr[0]);

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.