how to show a certain position in javascript

//How to print a specific element in javascript



/*====DESCRIPTION starts here=====
You can output a specific element or position of a list/array by 
using the output statement which is console.log(). Within it, type in the
name of the array in which you are dealing with, and specify with brackets
after the array name, enter the number of the 
position you want to output. Note though that as computers
count beginning from 0, you will have to subtract
1 from the original position we percieve. 
  ====DESRCIPTION ends here=======*/

//====EXAMPLE 1 STARTS HERE=========
//Using an integer to output a specific element/position of an array.
//array named "arr" which consists of 4 elements which are integers.
var arr = [3,4,5,2]
console.log(arr[2]) //Outputs "5" because 5 is the second (or third) element of the array.
//====EXAMPLE 1 ENDS HERE=========

//====EXAMPLE 2 STARTS==========
//Using a variable to output a specific element/position of an array.
//array named "arr" which consists of 4 elements which are integers.
var arr = [8,9,3,5]
//A variable named "i" which stores a value of an integer, 2.
	//Will be used to output the second element of the array.
var x = 0
console.log(arr[x]) //Outputs "8" since 8 is the 0 (or first) elemnt of the arary.
//====EXAMPLE 2 ENDS HERE==========

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source